Use a nx2 matrix to indicate desired positions on another matrix

2 次查看(过去 30 天)
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"

采纳的回答

Matt J
Matt J 2012-10-31
var(sub2ind(size(var), pos(:,1), pos(:,2))) = newvalue;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by