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

47 ビュー (過去 30 日間)
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 件のコメント
Stephen23
Stephen23 2021 年 8 月 29 日
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

サインインしてコメントする。

採用された回答

Ive J
Ive J 2021 年 8 月 28 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by