Hi, I have
a=[1 2; 3 4; 5 6];
for m=1:4
if m<=2
b=a([2 3],:)
else
c=a([1 2],:)
end
end
I want to keep the answer for every loop, for example, I want to know the ouptut when m=1, m=2, m=3 and m=4 respectively. How am i going to do this?
Thanks.

 채택된 답변

Sara
Sara 2014년 6월 3일

0 개 추천

a=[1 2; 3 4; 5 6];
result = cell(4,1);
for m=1:4
if m<=2
result{m}=a([2 3],:)
else
result{m}=a([1 2],:)
end
end

댓글 수: 3

Hi sara,
my output is :
result =
[2x2 double]
[2x2 double]
[2x2 double]
[2x2 double]
Is it possible for me to know the variables in this [2x2 double] array?
doc cell2mat
Replace mynum with the index you're interested in:
result{mynum}
e.g., result{3} will give you the result for m=3

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

추가 답변 (0개)

질문:

2014년 6월 3일

댓글:

2014년 6월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by