How to vectorize the following code?

Hi all,
How can I vectorize the following code?
a=struct('cycles',[])
a(1).cycles=[rand(15,20];
a(2).cycles=[rand(15,20];
a(3).cycles=[rand(15,20];
for i=1:length(a)
totalnum(i)=sum(a(i).cycles)
end
Where totalnum should be a [3,20] array.
Thanks
cheers

2 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 6 月 1 日
What is a?
pietro
pietro 2014 年 6 月 1 日
You're on right, I have just edited the question. thanks

サインインしてコメントする。

 採用された回答

dpb
dpb 2014 年 6 月 1 日

0 投票

reshape(sum([a.cycles]),length(a),[]).'

その他の回答 (0 件)

カテゴリ

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

製品

タグ

質問済み:

2014 年 6 月 1 日

回答済み:

dpb
2014 年 6 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by