Indexing problem with matrices

1 visualización (últimos 30 días)
Francesco Cattaneo
Francesco Cattaneo el 4 de Ag. de 2020
Comentada: Francesco Cattaneo el 7 de Ag. de 2020
Hi everyone, I've got a problem, I don't know if there's an easy solution.
I have two matrices:
A = [3 5 9 6 ; 2 1 13 6 ; 6 8 52 4 ; 13 6 8 22 ];
GRID = [linspace(1,100,100); rand(1,100); rand(1,100)]';
Each element of A is the index of the point of a structure. GRID sorts every point of the structure and associates the x and y coordinate in the 2nd and 3rd column.
The aim is to create a matrix Ax in which actually every element is the x coordinate of the correspondant A element (taken from the 2nd colum of GRID) and a a matrix Ay in which every element is the y coordinate of the correspondant A element (taken from the 3rd colum of GRID).
I cant use a for because A is very big and it takes too long. I dont know how to do.
Thanks to everyone

Respuesta aceptada

Bruno Luong
Bruno Luong el 4 de Ag. de 2020
Editada: Bruno Luong el 4 de Ag. de 2020
A = [3 5 9 6 ; 2 1 13 6 ; 6 8 52 4 ; 13 6 8 22 ];
GRID = [linspace(1,100,100); rand(1,100); rand(1,100)]'
Code
[tf,loc]=ismember(A,GRID(:,1)); % or possible loc = A, if it's already index
Ax=nan(size(loc)); Ax(tf)=GRID(loc(tf),2);
Ay=nan(size(loc)); Ay(tf)=GRID(loc(tf),3);
Result
Ax
Ay

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by