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

조회 수: 46 (최근 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 CenterFile Exchange에서 Interactive 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