New Workplace variable from Table

7 ビュー (過去 30 日間)
Nathan Kelly
Nathan Kelly 2023 年 3 月 9 日
回答済み: Steven Lord 2023 年 3 月 9 日
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?

採用された回答

Steven Lord
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.

その他の回答 (1 件)

Cameron
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)
38 43 38 40 49

カテゴリ

Help Center および File ExchangeTables についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by