Printing a MATLAB table on the console which contains both characters and ints

46 visualizzazioni (ultimi 30 giorni)
I am trying to print a table on the console (using the table function) that displays both characters and numerical values in the same table. My current code is shown below. How do I make it such that I can remove the { and ' characters from all of the parameters in the "Name of Value" column? Any help would be greatly appreciated. Thank you
col = {'Name of value', 'Value'};
titles = {'Mileage (km)', 'Tire Pressure (bars)', 'License Points'}';
vals = [20000, 2.4, 3]';
configTable = cell2table([titles, num2cell(vals)], 'VariableNames', col);
disp(configTable)
Name of value Value ________________________ _____ {'Mileage (km)' } 20000 {'Tire Pressure (bars)'} 2.4 {'License Points' } 3
  1 Commento
Stephen23
Stephen23 il 29 Ago 2021
Use categorical or char:
X = ["Mileage (km)"; "Tire Pressure (bars)"; "License Points"];
Y = [20000; 2.4; 3];
T = table(char(X), Y, 'VariableNames', ["Name of value", "Value"])
T = 3×2 table
Name of value Value ____________________ _____ Mileage (km) 20000 Tire Pressure (bars) 2.4 License Points 3

Accedi per commentare.

Risposta accettata

Ive J
Ive J il 28 Ago 2021
One simple way is to convert them to categorical, but if you're doing something with that variable, extra care should be taken.
col = {'Name of value', 'Value'};
titles = {'Mileage (km)', 'Tire Pressure (bars)', 'License Points'}';
vals = [20000, 2.4, 3]';
configTable = cell2table([titles, num2cell(vals)], 'VariableNames', col);
configTable.(1) = categorical(configTable.(1));
disp(configTable)
Name of value Value ____________________ _____ Mileage (km) 20000 Tire Pressure (bars) 2.4 License Points 3

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by