www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SortRowsofTablebyRowNamesExample.m

    %% Sort Rows of Table by Row Names  

%% 
% Create a table with four variables listing patient information for five
% people. 
LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];

tblA = table(Age,Height,Weight,BloodPressure,'RowNames',LastName)  

%% 
% Sort the rows of the table by the row names and return an index vector,
% such that |tblB = tblA(index,:)|. 
[tblB,index] = sortrows(tblA,'RowNames') 

%%
% The |sortrows| function sorts the rows in ascending order by the row names.