フィルターのクリア

Sort Table Variable with Cell Arrays

4 ビュー (過去 30 日間)
Felipe Dicker
Felipe Dicker 2024 年 5 月 13 日
回答済み: Voss 2024 年 5 月 13 日
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 Center および File ExchangeTables についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by