Change Variable Names of a Table
43 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tobias Pfeifer
am 17 Mär. 2021
Kommentiert: Steven Lord
am 17 Mär. 2021
Hi,
i have a Table, that consists of temperature data measured with a specific amount of sensors. Now i want to change the Variable Names of the columns with the sensor data to Sensor 1.......Sensor n. The first 3 columns should not be renamed. I want to create a code that gets the number of the sensors and renames them itself. This code should be usable for different measurement without the need to rewrite the code. Thanks in advance!
Akzeptierte Antwort
Cris LaPierre
am 17 Mär. 2021
Variable names exist in the properties of the table.
tblName.Properties.VariableNames
Use indexing to set just the names you want. For example, consider the folowing code for renaming 5 sensors starting at variable 4.
% Create table of 5 rows, 10 variables
A=array2table(rand(5,10))
% Create variable names for 5 sensors
n=5;
sNames = "Sensor " + (1:n);
% rename variables starting at Var4, and including n continguous variables.
A.Properties.VariableNames(4:4+n-1)=sNames
2 Kommentare
Steven Lord
am 17 Mär. 2021
As of release R2020a there's a function named renamevars for renaming table and timetable variables.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!