MATLAB: Sum of array in structure.

arraystructsum

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.)

Best Answer

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