# how to access cell array data with single for loop

37 views (last 30 days)
singh on 27 Apr 2015
two cell array like
A={1,2,3,4,5} %cell array
B={11,12,13,14,15} %cell array
for i=1:length(A)
C %variable
D %variable
end
in first iteration C take 1 from A and D take 11 from B
second iteration C take 2 from A and D take 12 from B
So on
use only single for loop
##### 2 CommentsShowHide 1 older comment
singh on 27 Apr 2015
i have some problem because actual cell array value is below
A{:}
17
6 11
1 9
B{:}
1 9
6 11
17

per isakson on 27 Apr 2015
Edited: per isakson on 27 Apr 2015
C = cell( size(A));
D = cell( size(B));
for ii=1:length(A)
C(ii) = A(ii);
D(ii) = B(ii);
end
&nbsp
Without the loop - vectorized
C = A;
D = B;
DEEPAK PHCSFI17041149 on 29 Nov 2017
Thanks for the guidance Isak.

Michael Haderlein on 27 Apr 2015
You mean like
for cnt=1:length(A)
C=A{cnt};
D=B{cnt};
end
Actually, there is no need for cell arrays here. In case this is just a simplified example and A and B will be of different kind in your final program, it's fine. Otherwise, I would make A and B just normal double arrays.