New Workplace variable from Table
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Steven Lord
il 9 Mar 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 Commenti
Più risposte (1)
Cameron
il 9 Mar 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 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!