Use a nx2 matrix to indicate desired positions on another matrix

조회 수: 1 (최근 30일)
Raldi
Raldi 2012년 10월 31일
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