for loop vectorization using cells

3 views (last 30 days)
I am trying to vectorize following loop:
for i = 1: size(s{2},1)
locCOR(i) = 0;
for j = 1 : size(s,2)
locCOR(i) = locCOR(i) + s{j}(i);
end
end
where s is a cell
Columns 1 through 4
[36x1 double] [36x1 double] [36x1 double] [36x1 double]
Columns 5 through 8
[36x1 double] [36x1 double] [36x1 double] [36x1 double]
Can somebody help me out?

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 30 Jul 2015
Edited: Azzi Abdelmalek on 30 Jul 2015
s=arrayfun(@(x) randi(9,36,1),1:10,'un',0) %Example
locCOR=sum(cell2mat(s),2)

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!