Setting array indices to a vector of values

조회 수: 3 (최근 30일)
David House
David House 2019년 12월 13일
댓글: David House 2019년 12월 17일
I am coming from IDL, and in that language I can write something like this:
Temp(xVal, yVal) = VectorOfValues
Where 'Temp' is an array (say 600x300)
xVal = a vector of values that I am using as the x indices
yVal = a vector of values that I am using as the y indices
VectorOfValues = a vector of values the same length as xVal and yVal
Basically I am trying to set the certain indices indicated by xVal and yVal to the values that are in VectorOfValues. I get that I could make a for loop to go through each one but is there another way to do this?

채택된 답변

the cyclist
the cyclist 2019년 12월 13일
You can use sub2ind command to convert the subscripted indices (xVal,yVal) into a single linear index into the array.
  댓글 수: 1
David House
David House 2019년 12월 17일
Thanks, that worked. An extra line needed compared to IDL but works the same :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by