Sort table with a specific order

조회 수: 5 (최근 30일)
Iugo
Iugo 2021년 6월 12일
댓글: Iugo 2021년 6월 13일
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!

채택된 답변

Walter Roberson
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,:);
  댓글 수: 1
Iugo
Iugo 2021년 6월 13일
Thank you so much @Walter Roberson!! Nailed it!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics and Visualization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by