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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by