Sort table with a specific order

11 Ansichten (letzte 30 Tage)
Iugo
Iugo am 12 Jun. 2021
Kommentiert: Iugo am 13 Jun. 2021
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!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 13 Jun. 2021
[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,:);

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by