loop problems on for cycle

조회 수: 1 (최근 30일)
André Sousa
André Sousa 2014년 5월 22일
답변: Image Analyst 2014년 5월 22일
Hi there! This is the code I have:
aa=rand(2,2,2); aa(1,1,1)=4; aa(2,1,1)=3; aa(1,2,1)=6; aa(2,2,1)=2; aa(1,1,2)=7; aa(2,1,2)=7; aa(1,2,2)=5; aa(2,2,2)=4; aa; dimention_aa=size(aa);
aareshaped=reshape(aa,[2,4]);
ii=rand(4,1); ii(1,1)=3; ii(2,1)=4; ii(3,1)=5; ii(4,1)=5;
for(j=(ii(1):ii(end)))
ind_reshaped=find(aareshaped==j);
irv=zeros(1,size(ind_reshaped));
irv(1,:)=ind_reshaped
[R1, C1, S1]=ind2sub(dimention_aa,ind_reshaped)
roi_mat=zeros(dimention_aa);
roi_mat(R1,C1,S1)=1
end
I want to store each [R1,C1,S1](a set of positions) on a different vector, but it just overwrites each set. What am I doing wrong?

답변 (1개)

Image Analyst
Image Analyst 2014년 5월 22일
Index them:
[R1(j), C1(j), S1(j)] = ind2sub(dimention_aa,ind_reshaped);

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by