www.gusucode.com > stats 源码程序 matlab案例代码 > stats/ZScoresofaDataMatrixExample.m
%% Z-Scores of a Data Matrix % Compute $z$-scores using the mean and standard deviation computed along % the columns or rows of a data matrix. %% % Load the sample data. load flu %% % The dataset array |flu| is loaded in the workplace. |flu| has 52 observations % on 11 variables. The first variable contains dates (in weeks). The other % variables contain the flu estimates for different regions in the U.S. %% % Convert the dataset array to a data matrix. flu2 = double(flu(:,2:end)); %% % The new data matrix, |flu2|, is a 52-by-10 double data matrix. The rows % correspond to the weeks and the columns correspond to the U.S. regions % in the data set array |flu|. %% % Standardize the flu estimate for each region (the _columns_ of |flu2|). Z1 = zscore(flu2,[ ],1); %% % You can see the $z$-scores in the variable editor by double-clicking on % the matrix |Z1| created in the workspace. %% % Standardize the flu estimate for each week (the _rows_ of |flu2|). Z2 = zscore(flu2,[ ],2);