loop problems on for cycle
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (1)
Image Analyst
le 22 Mai 2014
Index them:
[R1(j), C1(j), S1(j)] = ind2sub(dimention_aa,ind_reshaped);
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!