Hi,
I have this for loop and it's working fine. But the output (A) is a 2x2 matrix. How can i store the outputs in A1,A2....A183 like for all i's in the loop.
for i=122:1:305
A=DamithCount(S1(i,:),S1(i+1,:));
end
Thanks in advance for help.

 채택된 답변

Matt J
Matt J 2014년 5월 19일
편집: Matt J 2014년 5월 19일

0 개 추천

This will store them in slices A(:,:,1), A(:,:,2), ...A(:,:,184) of a 3D array, a much better data organization than A1,...,A184.
for i=122:305
A(:,:,i-121)=DamithCount(S1(i,:),S1(i+1,:));
end

댓글 수: 4

Damith
Damith 2014년 5월 19일
Thanks a lot. it worked.
Damith
Damith 2014년 5월 19일
Hi Matt,
I am trying to access the 4 elements in A(:,:,1) upto A(:,:,184). For example if I want to sum the 1,1 and 2,1, how can I do that. I need to do the same for 1,2 and 2,2.
Please let me know.
Thanks.
Image Analyst
Image Analyst 2014년 5월 20일
How is that 4 elements instead of 184 elements? And why are you giving only two 2-D coordinates instead of four 3-D coordinates?
By the way, you might need to use squeeze().
@Damith,
If you mean you want to sum across slices, you would simply do
Asum=sum(A,3)
Note how much harder this would have been if you had stored in separate matrices A1,...A184 !

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

추가 답변 (1개)

Sara
Sara 2014년 5월 19일

0 개 추천

for i = 122:305
assignin('base',['A',num2str(i)],DamithCount(S1(i,:),S1(i+1,:)));
end
Look up assignin to be sure to use the right workspace.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2014년 5월 19일

댓글:

2014년 5월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by