Sorting a cell array of string, based on the order of another
22 ビュー (過去 30 日間)
古いコメントを表示
I have 2 cell array of string. The content of the cells is exactly the same, only the order is different.
I want to sort one, without changing the order of the other.
0 件のコメント
採用された回答
Walter Roberson
2011 年 2 月 23 日
[tf, idx] = ismember(B,A);
Places where tf are false are places where B is not in A. And of course, B might not cover all of A. If you know that B covers exactly A, then B(idx) should be the same as A
その他の回答 (3 件)
Walter Roberson
2011 年 2 月 22 日
Your title and your description do not agree. Your description has a trivial answer ("just don't use the second variable") so I will answer based on your title;
[sortedvals, sortidx] = sort(FirstCell);
newCell = SecondCell(sortidx);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!