how to access cell array data with single for loop

조회 수: 4(최근 30일)
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
singh
singh 2015년 4월 27일
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
per isakson 2015년 4월 27일
편집: per isakson 2015년 4월 27일
C = cell( size(A));
D = cell( size(B));
for ii=1:length(A)
C(ii) = A(ii);
D(ii) = B(ii);
end
&nbsp
Addendum
Without the loop - vectorized
C = A;
D = B;
  댓글 수: 4
DEEPAK PHCSFI17041149
DEEPAK PHCSFI17041149 2017년 11월 29일
Thanks for the guidance Isak.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Michael Haderlein
Michael Haderlein 2015년 4월 27일
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.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by