Extract Variable/column with variable name from table
Ältere Kommentare anzeigen
Hello,
I don't know how to extract a column with its variable name from a Matlab table.
I want to extract columns and not have to rename them afterwards in order to recreate a similar table bbut with only the column I want.
I need to extract them one at the time and the data types are different from one column to another.
I've tried different ways and read the matlab documentation but haven't found any solution.
Could you please help me? :)
Akzeptierte Antwort
Weitere Antworten (1)
Bob Thompson
am 16 Sep. 2019
1 Stimme
I believe you can get this as a return.
T.Properties.VariableNames % T is the table variable
Additionally, because you're putting them into another table, if you just extract the specific columns you want the new table, and they will carry the variable names with them.
>> A = randi(100,10,4);
>> A = array2table(A);
>> A.Properties.VariableNames
ans =
1×4 cell array
{'A1'} {'A2'} {'A3'} {'A4'}
>> B = A(:,[2,4]);
>> B.Properties.VariableNames
ans =
1×2 cell array
{'A2'} {'A4'}
2 Kommentare
yvesvincent abgrall
am 16 Sep. 2019
Bob Thompson
am 16 Sep. 2019
As I mentioned, if you are extracting the column data into another table then the variable name will follow with it. Just put the information into a table class variable, which can be done most easily by indexing the portion of the original table that you want into a clean variable.
Kategorien
Mehr zu Tables finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
