Borrar filtros
Borrar filtros

I have 2D array of size 16*16 stored in a variable temp and I have set of x and y values x=[1 2 3]; y=[4 5 6]; I want to extract values from temp variable indexed by (x,y)=(1,4) (2,5) (3,6) without using for loop. Thank you.

3 visualizaciones (últimos 30 días)
I have 2D array of size 16*16 stored in a variable temp and I have set of x and y values x=[1 2 3]; y=[4 5 6]; I want to extract values from temp variable indexed by (x,y)=(1,4) (2,5) (3,6) without using for loop. Thank you.

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Dic. de 2015
values = YourMatrix( sub2ind(size(YourMatrix), x, y) );
The faster form of this for a 16 x 16 matrix is
YourMatrix(x + (y-1)*16)

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by