Let us say that we have a matrix A1 and two vectors v1 and v2 as follow:
A1=zeros(5, 5); v1=[1 2 3]; v2=[5 5 4];
Is there a way to replace the
Convert your vectors into linear indices:
A1=zeros(5, 5); v1=[1 2 3]; v2=[5 5 4]; ind=sub2ind(size(A1), v1, v2); A1(ind(1))=1 A1 = 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
etc.