Setting array indices to a vector of values

5 visualizaciones (últimos 30 días)
David House
David House el 13 de Dic. de 2019
Comentada: David House el 17 de Dic. de 2019
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?

Respuesta aceptada

the cyclist
the cyclist el 13 de Dic. de 2019
You can use sub2ind command to convert the subscripted indices (xVal,yVal) into a single linear index into the array.
  1 comentario
David House
David House el 17 de Dic. de 2019
Thanks, that worked. An extra line needed compared to IDL but works the same :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by