Hi,
As you can see from the data, whenever you apply sortrows to your table, by giving your column name as 'v' data will be sorted based on the first column of your merged column 'v'.
As a workaround, you can use 'splitvars' method to update your table and apply sortrows, then later merge your table which you need as a final result using 'mergevars'.
Here is the code to it:
a = [0.88517 ;0.91329;0.79618;0.098712;0.26187];
v = [ 0.33536 0.65376 0.89092; 0.67973 0.49417 0.33416; 0.13655 0.77905 0.69875; 0.72123 0.71504 0.19781; 0.10676 0.90372 0.030541];
tbl = table(a,v)
tbl1 = splitvars(tbl);
tbl1 = sortrows(tbl1,[4]);
finaltbl = mergevars(tbl1,[2 3 4],'NewVariableName','v');
Hope this helps!
2 Comments
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/571405-sort-rows-of-a-table-by-column-within-a-variable#comment_951835
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/571405-sort-rows-of-a-table-by-column-within-a-variable#comment_951835
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/571405-sort-rows-of-a-table-by-column-within-a-variable#comment_951841
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/571405-sort-rows-of-a-table-by-column-within-a-variable#comment_951841
Sign in to comment.