Sort table with a specific order
14 次查看(过去 30 天)
显示 更早的评论
Hello everyone!
I have a table with two columns, the first is called ScanID , which contains the id's of some patients, and the second is called Site, which contains the site where the patients belong, going from 1 to 8. What I want is to order the rows of that table based on that Site column values, with the following order: 3,4,5,6,7,1,8.
How can I achieve this?
Thank you so much!
0 个评论
采纳的回答
Walter Roberson
2021-6-13
[found, idx] = ismember(T.Site, [3,4,5,6,7,1,8]);
if any(~found)
error('Site not on approved list, first at row %d', find(~found,1));
end
[~, sortorder] = sort(idx);
newT = T(sortorder,:);
更多回答(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!