uC = zeros(1,length(X));
for loop1 = 1:length(X)
uC(loop1) = sum(X(loop1).Y);
end
Any other/proper/quick way to do this? (Note: length of all X.Y is not same.)

 採用された回答

Elias Gule
Elias Gule 2018 年 1 月 3 日

0 投票

try this.
uC = arrayfun(@(v) sum(v.Y),x)

4 件のコメント

Pramit Biswas
Pramit Biswas 2018 年 1 月 3 日
Thanks, learned a new way. Please change 'x' to 'X' to comply with the question.
Stephen23
Stephen23 2018 年 1 月 3 日
Note that this will be slower than a loop with a preallocated output array.
Pramit Biswas
Pramit Biswas 2018 年 1 月 3 日
oops!!! Is this function only to reduce code? Any other ways?
Elias Gule
Elias Gule 2018 年 1 月 16 日
Yep!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by