MATLAB Answers

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

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

로그인 to comment.

답변(1개)

KSSV
KSSV 26 Feb 2020
편집: KSSV 27 Feb 2020 2:52
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 2:53
It should give you the matrix...check, I have edited the answer.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by