working with multiple matrix avoiding "for"

I have 253 vertically pasted matrix of size 221x431 (final dimensión of 55913x431). I would like to calculate the coefficient of variation (standard deviation/mean) of each element of the matrix, obtaining a final matrix of size 221x431. I have the following code which works but I would like to know if I could do it in a more simple and efficient way without using "for". Could you give me any suggestion? thank you for your help.
% b -> start matrix, size (55913,431)
for col = 1 : 431
for r = 1 : 221
m =b(r: 221 : 55913,col);
variation(r,col)= std(m)/mean(m);
end
end

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 6 日
編集済み: Azzi Abdelmalek 2014 年 8 月 6 日

1 投票

b=rand(55913,431);% b is your matrix
a=permute(reshape(b',431,221,[]),[2 1 3]);
variation=std(a,0,3)./mean(a,3);
I tested the two methods speed
With the for loop : Elapsed time is 7.797265 seconds.
Without loop : Elapsed time is 0.479849 seconds.

その他の回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2014 年 8 月 6 日

0 投票

k = 221;
s = size(b,1);
b2 = reshape(b,k,s/k,[]);
variation = squeeze(std(b2,0,2)./mean(b2,2));
Jose Luis
Jose Luis 2014 年 8 月 7 日

0 投票

Thank you for the answers, they were very helpful! Jose

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

質問済み:

2014 年 8 月 6 日

回答済み:

2014 年 8 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by