Sum all answers from structured array field

Hi,
I'm trying to sum all values from one field of a structured array:
(X(k(1:end)).NumberSamples)
ans =
3692
ans =
3420
ans =
2470
ans =
3382
I want to add these values together, however I can't use
sum(X(k(1:end)).NumberSamples)
Is there a way around this that sums the answers from the original input (X(k(1:end)).NumberSamples)?
Thanks

 採用された回答

Guillaume
Guillaume 2017 年 11 月 1 日
編集済み: Guillaume 2017 年 11 月 1 日

0 投票

Simply,
sum([X(k).NumberSamples])
Note the use of [] to convert the comma separated list returned by X(k).NumberSamples into a vector that can be summed.

1 件のコメント

BOB
BOB 2017 年 11 月 1 日
Perfect, thank you for the fast response!

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

BOB
2017 年 11 月 1 日

コメント済み:

BOB
2017 年 11 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by