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

51 visualizaciones (últimos 30 días)
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 comentario
Stephen23
Stephen23 el 29 de Ag. de 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

Iniciar sesión para comentar.

Respuesta aceptada

Ive J
Ive J el 28 de Ag. de 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

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by