Zscore array subset

I am calculating a simple zscore, across my rows for a matrix. What I want to return, in ONE line of code, is just the last column of zscores. In other wordse I am using the code below where I would like a zscore for today, based off a trailing 252 day period. What I get with the function to the right of the equals sign is the full matrix of zscores of Nrows X 252 columns.
c=252;
SP_Zscores(:,c) = zscore(SP_MovAvg(:,c-251:c),1,2);
Thanks for the help, Brian

 채택된 답변

Oleg Komarov
Oleg Komarov 2012년 4월 4일

0 개 추천

You won't be able to use zscore in a one-liner:
"Z = zscore(X) returns a centered, scaled version of X, the same size as X"
Doing it manually:
(SP_MovAvg(:,c) - mean(SP_MovAvg(:,c-251:c),2))./std(SP_MovAvg(:,c-251:c),1,2)

댓글 수: 2

Brian
Brian 2012년 4월 4일
What does the period do right before the division sign? I see that it trims the data set to one column but why?
Thanks a lot,
Brian
Oleg Komarov
Oleg Komarov 2012년 4월 4일
The last column only is normalized, i.e. SP_MovAvg(:,c).
The ./ is the elementwise division (see the help for details).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품

질문:

2012년 4월 4일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by