sorting a matrix according to another matrix

조회 수: 2 (최근 30일)
joseph Frank
joseph Frank 2012년 2월 24일
편집: Azzi Abdelmalek 2013년 10월 23일
Hi,
I have a 2x200000 matrix A where the 2nd column is an ID column.Then I have another 6x200000 matrix B in which also the first column is an ID column . The ID column of A has the same IDs as the ID column in B, however with a different order. Is it possible to sort the whole matrix B according to the column matrix of A? for example: A=[ 0.3 1;0.4 2; 0.1 3] and B=[1 6; 3 8 ;2 11]; is it possible to sort B according to the 2nd column of A (IDs) to get B=[1 6; 2 11; 3 8]; where the first column in B is also a column of the same IDs of A?
  댓글 수: 1
Andrei Bobrov
Andrei Bobrov 2012년 2월 24일
in size of A: 2 - rows, 200000 - columns?

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

채택된 답변

Sukuchha
Sukuchha 2012년 2월 24일
A=[ 0.3 1;0.4 2; 0.1 3]
B=[1 6; 3 8 ;2 11]
[tf, loc] = ismember(A(:,2), B(:,1))
B_value = B(:,2);
result=[ A(:,2) B_value(loc)]

추가 답변 (0개)

카테고리

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