www.gusucode.com > stats 源码程序 matlab案例代码 > stats/ZScoresofTwoDataVectorsExample.m

    %% Z-Scores of Two Data Vectors  
% Compute and plot the $z$-scores of two data vectors, and then compare
% the results.   

%% 
% Load the sample data. 
load lawdata

%%
% Two variables load into the workspace: |gpa| and |lsat|.  

%% 
% Plot both variables on the same axes. 
plot([gpa,lsat])
legend('gpa','lsat','Location','East')    

%%
% It is difficult to compare these two measures because they are on a very
% different scale.  

%% 
% Plot the $z$-scores of |gpa| and |lsat| on the same axes. 
Zgpa = zscore(gpa);
Zlsat = zscore(lsat);
plot([Zgpa, Zlsat])
legend('gpa z-scores','lsat z-scores','Location','Northeast')    

%%
% Now, you can see the relative performance of individuals with respect
% to both their |gpa| and |lsat| results. For example, the third individual’s
% |gpa| and |lsat| results are both one standard deviation below the sample
% mean. The eleventh individual’s |gpa| is around the sample mean but has
% an |lsat| score almost 1.25 standard deviations above the sample average.  

%% 
% Check the mean and standard deviation of the $z$-scores you created. 
 mean([Zgpa,Zlsat])  

%%  
 std([Zgpa,Zlsat]) 

%%
% By definition, $z$-scores of |gpa| and |lsat| have mean 0 and standard
% deviation 1.