MATLAB Answers


Use a nx2 matrix to indicate desired positions on another matrix

Asked by Raldi
on 31 Oct 2012
Hello everyone,
I have a quick question, how can i use the matrix lets say
pos = [1 2; 3 3];
as a guide to change the values of another matrix lets say
val = zeros(3);
avoiding for loops. What i want is something like var(pos(1,end,:)) = "some value"


Sign in to comment.

1 Answer

Answer by Matt J
on 31 Oct 2012
 Accepted Answer

var(sub2ind(size(var), pos(:,1), pos(:,2))) = newvalue;

  1 Comment

Sign in to comment.