Hi I have an object A which contains 9 vectors all of size [1 3], three dimensional vectors. How do I sum all of these to create a new vector of size [1 3] i.e. how to I take the contribution of each vector, and sum each of their contributions to give me a final vector. Thanks in advance. My vectors are stored in a cell array. How A is defined:
ri = Rix{1,1};
rj = Riy{1,1};
vec2 = @(i)[ri(i), rj(i), 0];
A = arrayfun(vec2, reshape(1:numel(ri), size(ri)), 'UniformOutput', 0);
and this is what I have tried so far:
B = cellfun(@(A)nansum(A(:))'un', 0);
with this error
??? b = cellfun(@(distance)nansum(distance(:))'un', 0); | Error: Unexpected MATLAB expression.
cellfun
is not the way to go here, because your resultis only one vector element, not several vectors. Like @Vidar suggested,cell2mat
is a good way to solve this problem. Regardless to your question, however: you have a syntax error withcellfun
. Read this documentation if you want to use it properly. – Eitan T