Sort Table Variable with Cell Arrays

4 次查看(过去 30 天)
So I have a table being printed out in AppDesigner and I'd like to sort it based on the alphabetical order of the parameters in the first column. I've tried using sortrows but I get the following error:
An error occurred when sorting rows of the variable 't2', whose type is 'cell'.
Caused by:
Cell elements must be character arrays.
Without sorting anything the first few lines of the table so far look like this, with the cells in blue actually being a single column (as if it was merged like in an Excel sheet):
For coding I've done the following:
t1 = {'Log Name';'Parameter';'Distance (m)';'RPM';'Speed (km/h)';'Lat. Accel. (G)'};
t2 = [{' ' id_1 ' '};{'Min Value' 'Max Value' 'Avg/Single Value'};{'-' '-' max(dist_1)};{min(RPM_1) max(RPM_1) mean(RPM_1,'omitnan')};...
{min(v_front_1) max(v_front_1) mean(v_front_1,'omitnan')};{min(ay_1) max(ay_1) mean(ay_1,'omitnan')}];
t = table(t1,t2);
I guess it has something to do with the fact that I'm using cell arrays (which I don't fully understand) to get that "merged cell" look like in Excel but I couldn't find a better way to do it. Thanks in advance.

回答(1 个)

Voss
Voss 2024-5-13
t = table(t1,t2);
[~,idx] = sort(t1(3:end));
t = t([1; 2; 2+idx],:);

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by