New Workplace variable from Table
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Steven Lord
2023-3-9
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 个评论
更多回答(1 个)
Cameron
2023-3-9
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!