can someone help me loop this??
Show older comments
n=4 t=1:21
std_t1 = (((pc(1,:)- MA(1,:)).^2)/(n-1)+...
((pc(2,:)- MA(1,:)).^2)/(n-1)+...
((pc(3,:)- MA(1,:)).^2)/(n-1)+...
((pc(4,:)- MA(1,:)).^2)/(n-1)).^(1/2)
std_t2 = (((pc(2,:)- MA(2,:)).^2)/(n-1)+...
((pc(3,:)- MA(2,:)).^2)/(n-1)+...
((pc(4,:)- MA(2,:)).^2)/(n-1)+...
((pc(5,:)- MA(2,:)).^2)/(n-1)).^(1/2)
std_t3 = (((pc(3,:)- MA(3,:)).^2)/(n-1)+...
((pc(4,:)- MA(3,:)).^2)/(n-1)+...
((pc(5,:)- MA(3,:)).^2)/(n-1)+...
((pc(6,:)- MA(3,:)).^2)/(n-1)).^(1/2)
etc .. say I would like to continue this pattern for a total of 21 time periods
Accepted Answer
More Answers (2)
Walter Roberson
on 29 Sep 2013
T1 = reshape(pc, 4, size(pc,1)/4, []);
T2 = permute( reshape( repmat(MA,[4 1 1]), size(MA,1), 4, size(MA,2) ), [2 1 3] );
T3 = (T1 - T2).^2;
T4 = squeeze( sum(T3,1) );
T5 = sqrt(T4 ./ (n-1));
Now one of the dimensions of T5 corresponds to the stdx* index (that is, corresponds to the subscript of MA that you used), and the other dimension of T5 corresponds to the second dimension of pc and MA. Provided, that is, that I worked out all the manipulations properly in my head.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!