How do i sort table rows based on other table rows ?

조회 수: 15 (최근 30일)
ahmed obaid
ahmed obaid 2017년 6월 8일
답변: Andrei Bobrov 2017년 6월 8일
Dear experiences..
i have two tables.. A and B..
where table A involves ( id, num, var1 , var2).., and table B involves (num, var1.....varn).. i need to sort either table A rows based on table B num order or vise versa... how do i perform this task ?
thanks

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 6월 8일
[~,ii] = ismember(A.num,B.num);
B_sorted_as_A = B(ii,:);

추가 답변 (1개)

Guillaume
Guillaume 2017년 6월 8일
sorting A according to B:
[isinB, whereinB] = ismember(tableA.num, tableN.num);
assert(all(isinB), 'some rows of A are not found in B);
[~, order] = sort(whereinB);
sortedtableA = tableA(order, :);

카테고리

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