New Workplace variable from Table
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nathan Kelly
am 9 Mär. 2023
Beantwortet: Steven Lord
am 9 Mär. 2023
Say I have a Table with Variable headers for each column such as below.
Tp = table(categorical({'M';'M';'F';'F';'F'}),[38;43;38;40;49],...
[71;69;64;67;64],[176;163;131;133;119],...
'VariableNames',{'Gender' 'Age' 'Height' 'Weight'})
If I look at the table in the variable window I can select the column by hand and create a new workplace variable/array from the data , named after the headers (VariableNames',{'Gender' 'Age' 'Height' 'Weight'})) with the data of that variable.
Is there a way to code a script to do this without manually picking the columns? Or a way to create new workplace variables from list?
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 9 Mär. 2023
Is there a way to code a script to do this without manually picking the columns? Or a way to create new workplace variables from list?
Can you dynamically create variables with names automatically generated from table variable names? Yes.
Should you do this? The general consensus is no. That Answers post explains why this is generally discouraged and offers several alternative approaches.
Depending on what you want to do with those variables the varfun function may be of interest to you.
0 Kommentare
Weitere Antworten (1)
Cameron
am 9 Mär. 2023
Tp = table(categorical({'M';'M';'F';'F';'F'}),[38;43;38;40;49],...
[71;69;64;67;64],[176;163;131;133;119],...
'VariableNames',{'Gender' 'Age' 'Height' 'Weight'});
Age = Tp.Age;
Gender = Tp.Gender;
disp(Age)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical 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!