How can I fetch data from one matrix into another matrix?

1 visualización (últimos 30 días)
patcharapon kangwarnchokchai
patcharapon kangwarnchokchai el 26 de Feb. de 2020
Comentada: KSSV el 27 de Feb. de 2020
I have matrix A and B.
when
A=
4
1
2
1
B=
1 100 200
2 300 400
3 500 600
4 700 800
5 900 1000
and then I would like to make matrix C.
C=
4 700 800
1 100 200
2 300 400
1 100 200
I would like to use A as a base and then sort data form B by using first column of B.

Respuestas (1)

KSSV
KSSV el 26 de Feb. de 2020
Editada: KSSV el 27 de Feb. de 2020
A= [4
1
2
1] ;
B= [1 100 200
2 300 400
3 500 600
4 700 800
5 900 1000] ;
[idx,ia] = ismember(B(:,1),A) ;
C = B(idx,:)
C =
1 100 200
2 300 400
4 700 800
  2 comentarios
patcharapon kangwarnchokchai
patcharapon kangwarnchokchai el 27 de Feb. de 2020
Sorry, I have tried this, but matrix C show me like a boolean value.
KSSV
KSSV el 27 de Feb. de 2020
It should give you the matrix...check, I have edited the answer.

Iniciar sesión para comentar.

Categorías

Más información sobre Shifting and Sorting Matrices 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