MATLAB Answers

BOB
0

Sum all answers from structured array field

Asked by BOB
on 1 Nov 2017
Latest activity Commented on by BOB
on 1 Nov 2017
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

  0 Comments

Sign in to comment.

1 Answer

Answer by Guillaume
on 1 Nov 2017
Edited by Guillaume
on 1 Nov 2017
 Accepted Answer

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 Comment

Perfect, thank you for the fast response!

Sign in to comment.