I have
A=[1 ;2; 2; 3; 1]
and
B=[4; 1; 5; 2 ;3]
then I want to have
C=zeros(size(B),1);for i =1:size(B,1) C(A(i))=B(i);end
A, B and C are the same size and A contains the indices but not in order. Without a loop, we can do C(A)=B.
Now if I want to have (C is initialized properly at start )
C=zeros(3,5)for i =1:size(B,1) C(A(i),B(i))=5; %or any other value
end
C(A,B)=5 does not give the expected result. Is the principle not the same?
Best Answer