Sorting a cell array of string, based on the order of another
8 次查看(过去 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!