MATLAB Answers

sum of array in structure.

46 views (last 30 days)
Pramit Biswas
Pramit Biswas on 3 Jan 2018
Commented: Elias Gule on 16 Jan 2018
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.)

  0 Comments

Sign in to comment.

Accepted Answer

Elias Gule
Elias Gule on 3 Jan 2018
try this.
uC = arrayfun(@(v) sum(v.Y),x)

  4 Comments

Show 1 older comment
Stephen Cobeldick
Stephen Cobeldick on 3 Jan 2018
Note that this will be slower than a loop with a preallocated output array.
Pramit Biswas
Pramit Biswas on 3 Jan 2018
oops!!! Is this function only to reduce code? Any other ways?

Sign in to comment.

More Answers (0)


Translated by