필터 지우기
필터 지우기

How to change the name of a table and its headings?

조회 수: 9 (최근 30일)
Mahnoor
Mahnoor 2023년 7월 31일
편집: Star Strider 2023년 8월 9일
Hi
I am trying to change the name of table to Time duration of vehicle speed from Time_duration_vehicle_speed and its two column headings to Interval of speed (rpm) and Duration of speed (s) (all wihtout any underscores). I am not sure how to type the words properly or what the format is to get it be displayed in a normal format with spaces.
Any help would be appreciated, Thankyou.

답변 (2개)

Star Strider
Star Strider 2023년 7월 31일
편집: Star Strider 2023년 8월 9일
This should work in R2020b
Interval_of_speed_rpm = randn(5,1);
Duration_of_speed_sec = randn(5,1);
Time_duration_vehicle_speed = table(Interval_of_speed_rpm, Duration_of_speed_sec)
Time_duration_vehicle_speed = 5×2 table
Interval_of_speed_rpm Duration_of_speed_sec _____________________ _____________________ -1.1854 0.7449 -1.2668 -0.072663 0.41819 -0.28403 -1.182 -2.618 -0.82624 -0.38265
VN = Time_duration_vehicle_speed.Properties.VariableNames
VN = 1×2 cell array
{'Interval_of_speed_rpm'} {'Duration_of_speed_sec'}
Time_duration_vehicle_speed.Properties.VariableNames = cellfun(@(x)strrep(x, '_', ' '), VN, 'Unif',0)
Time_duration_vehicle_speed = 5×2 table
Interval of speed rpm Duration of speed sec _____________________ _____________________ -1.1854 0.7449 -1.2668 -0.072663 0.41819 -0.28403 -1.182 -2.618 -0.82624 -0.38265
EDIT — (9 Aug 2023 at 11:11)
There cannot be any spaces in the name of the table.
.

Voss
Voss 2023년 7월 31일
The name of the table has to be a valid MATLAB variable name ("Time_duration_vehicle_speed" is OK; "Time duration vehicle speed" is not), but the name of the variables in the table can be specified when you create the table. Here's one way to do that:
Interval_Of_Speed_rpm = rand(8,1);
Duration_Of_Speed_s = rand(8,1);
% Time_duration_vehicle_speed = table(Interval_Of_Speed_rpm,Duration_Of_Speed_s)
Time_duration_vehicle_speed = table(Interval_Of_Speed_rpm,Duration_Of_Speed_s, ...
'VariableNames',{'Interval (RPM)','Duration (s)'})
Time_duration_vehicle_speed = 8×2 table
Interval (RPM) Duration (s) ______________ ____________ 0.48931 0.90388 0.29423 0.13388 0.13504 0.63643 0.1675 0.94239 0.14342 0.29882 0.82155 0.99378 0.82174 0.63595 0.43448 0.25636
  댓글 수: 2
Mahnoor
Mahnoor 2023년 8월 1일
Thankyoub @Voss for the information, are the following lines necessary as the code runs without these as well:
Interval_Of_Speed_rpm = rand(8,1);
Duration_Of_Speed_s = rand(8,1);
Alos,when I do include these 2 lines, all of my values in the table in contrast to the orginal values.
Dyuman Joshi
Dyuman Joshi 2023년 8월 1일
No, that is random data, used to show as an example

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by