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

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

답변 (1개)

KSSV
KSSV 2020년 2월 26일
편집: KSSV 2020년 2월 27일
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
patcharapon kangwarnchokchai 2020년 2월 27일
Sorry, I have tried this, but matrix C show me like a boolean value.
KSSV
KSSV 2020년 2월 27일
It should give you the matrix...check, I have edited the answer.

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

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by