loop problems on for cycle

1 次查看(过去 30 天)
André Sousa
André Sousa 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 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by