I am having trouble with using accumarray in a for loop. Hers is my code so far:
for i = 1:length(files)
rng_x{i} = -0.3:0.06:0.3;
disc_x{i} = discretize(expData{i,1}(:,1),rng_x{i});
x_mean{i} = accumarray(disc_x{1,i}(:,1), expData{i,1}(:,1),[11 1], @mean);
end
expData is a 2745x1 cell array and one cell contains a 4757x6 double (see picture)
disc_x is a 1x4757 cell array and one cell contains a 4757x1 double.
When I put in the command window:
x_mean = accumarray(disc_x{1,5}(:,1), expData{5,1}(:,1),[11 1], @mean);
It works fine. But as soon as I am trying to loop over the cells I get error messages. Which is kinda logical since accumarray works down colums. But how can loop over the different cells?
4 Comments
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/590998-error-using-accumarray-in-for-loop-with-cell-array#comment_1002319
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/590998-error-using-accumarray-in-for-loop-with-cell-array#comment_1002319
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/590998-error-using-accumarray-in-for-loop-with-cell-array#comment_1002352
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/590998-error-using-accumarray-in-for-loop-with-cell-array#comment_1002352
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/590998-error-using-accumarray-in-for-loop-with-cell-array#comment_1002406
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/590998-error-using-accumarray-in-for-loop-with-cell-array#comment_1002406
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/590998-error-using-accumarray-in-for-loop-with-cell-array#comment_1002424
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/590998-error-using-accumarray-in-for-loop-with-cell-array#comment_1002424
Sign in to comment.