MATLAB Answers

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

조회 수: 1(최근 30일)
patcharapon kangwarnchokchai
댓글: KSSV 27 Feb 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.

  댓글 수: 0

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

답변(1개)

KSSV
KSSV 26 Feb 2020
편집: KSSV 27 Feb 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

patcharapon kangwarnchokchai
Sorry, I have tried this, but matrix C show me like a boolean value.
KSSV
KSSV 27 Feb 2020
It should give you the matrix...check, I have edited the answer.

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

Community Treasure Hunt

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

Start Hunting!

Translated by