how to substitute, in a table, variable names with the values of a vector
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
i have a table of 6 colums U and each colums have its title (Nation, valueA, valueB, valueC, valueD, valueE). I want to substitute the last 5 colums names with the numbers contained in the vector X.
X = [1 2 3 4 5 ]
U is 20x6
0 Kommentare
Antworten (1)
Sajid Afaque
am 2 Apr. 2021
for num = 2:5
table_name.Properties.VariableNames(num) = {'New substitute name here in this case X(num-1)'};
end
2 Kommentare
Steven Lord
am 2 Apr. 2021
The ability to specify table variable names that are not valid MATLAB identifiers was introduced in release R2019b. Prior to that all table variable names had to be valid MATLAB identifiers (as per the isvarname function.)
T = array2table(magic(4))
newVariableNames = {'aardvark', 'baboon', 'camel', 'dog'};
T.Properties.VariableNames = newVariableNames
Siehe auch
Kategorien
Mehr zu Whos 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!