How to sum up a member of a 3D struct for all elements?
2 ビュー (過去 30 日間)
古いコメントを表示
Dear Community,
I have a 3D struct, with several members. I would like to sum up a certain member (oipsc) of the struct for all elements. How I could do it? I've tried several methosds, but frankly I don't know the right command i.e. syntax. I'm relatively new to Matlab. I've attached a simple SumTest.m code to higlight my problem.
Tx for the kind help in advance,
best regards,
Andras
0 件のコメント
回答 (1 件)
Askic V
2023 年 2 月 12 日
編集済み: Askic V
2023 年 2 月 12 日
Do you really need this (implemented with loops):
[d1,d2,d3] = size(gridblock);
sum_oipsc = 0;
for i = 1:d1
for j = 1:d2
for k = 1:d3
sum_oipsc = sum_oipsc + gridblock(i,j,k).oipsc;
end
end
end
If that is the case, then the solution would be as simple as:
sum_oipsc2 = sum([gridblock(:).oipsc])
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!