How to sort a table (only 2 rows)

조회 수: 4 (최근 30일)
Peter Meier
Peter Meier 2020년 7월 27일
답변: dpb 2020년 7월 27일
Hello,
I have sorted a table. It works. But i dont want to sort the whole table i want to put the lowest value here -> 0 (column C) to the first row and the highest value here 258 to the last row. The whole row where 0 or 258 is should be changed to the first/ last row.
My Code:
T = struct2table( parameter.list); % convert the struct array to a table
sortedT = sortrows(T, 'value'); % sort the table by value
sortedS = table2struct(sortedT) % change it back to str
This Code sorts all rows of the table. From 0 to 258. (Column C)

답변 (1개)

dpb
dpb 2020년 7월 27일
[~,imin]=min(T.value);
[~,imax]=max(T.value);
T=[T(imin,:); T; T(imax,:)];
T([imin,imax],:)=[];
Or, save the two rows of interest, remove them from T and then add back.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by