This is my full code:
aa=rand(2,2,2)
aa(1,1,1)=5;
aa(2,1,1)=8;
aa(1,2,1)=3;
aa(2,2,1)=3;
aa(1,1,2)=7;
aa(2,1,2)=8; aa(1,2,2)=3;
aa(2,2,2)=3;
dimention_aa=size(aa); aareshaped=reshape(aa,[2,4])
ii=rand(3,1);
ii(1,1)=8;
ii(2,1)=3;
ii(3,1)=7;
for( l=(ii(1):ii(end))) ind_reshaped=find(aareshaped==l) [R1, C1, S1]=ind2sub(dimention_aa,find(aareshaped==l) k=[R1, C1, S1] x1=k(:,1) y1=k(:,2) z1=k(:,3) newMatrix = zeros(dimention_aa) for j = 1 : size(k, 1) newMatrix( x1(j) , y1(j) ,z1(j)) = 1 end % roi_mat(l,:)=x;
end %%%%%%%%%%%%%%%%%%%%%%%%%%%%Basically the k matrix(that has lines correspondent to xyz positions) is genereated by
[R1, C1, S1]=ind2sub(dimention_aa,find(aareshaped==l)
k=[R1, C1, S1]
And l is a vector with diferent numbers. How do I do the same procedure to go through every element of "l"; and then save the "newMatrix with the corresponding index? The code I wrote above, doesn't work quite well.. Regards
Best Answer