Borrar filtros
Borrar filtros

Sort Table Variable with Cell Arrays

4 visualizaciones (últimos 30 días)
Felipe Dicker
Felipe Dicker el 13 de Mayo de 2024
Respondida: Voss el 13 de Mayo de 2024
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.

Respuestas (1)

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

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by