フィルターのクリア

getting new tables from another

2 ビュー (過去 30 日間)
jean claude
jean claude 2018 年 10 月 26 日
コメント済み: Peter Perkins 2018 年 10 月 31 日
hi, how to get table just for smith; a table for william , and a table for johnson ? imagine i have many rows with different company names and i want to separate them, so getting a table for every company. Here is a simplified example
LastName = {'Smith';'Johnson';'William';'William';'Smith'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];
T = table(Age,Height,Weight,BloodPressure,...
LastName)
output wanted x =
Age Height Weight BloodPressure LastName
___ ______ ______ _____________ ________
38 71 176 124 93 'Smith'
49 64 119 122 80 'Smith'
for william
Age Height Weight BloodPressure LastName
___ ______ ______ _____________ _________
38 64 131 125 83 'William'
40 67 133 117 75 'William'
  2 件のコメント
Stephen23
Stephen23 2018 年 10 月 26 日
編集済み: Stephen23 2018 年 10 月 26 日
Splitting the data up rather defeats the purpose of using a table. Keeping the data all together will mean you can use neat table operations (like splitapply, findgroups, etc.) and will make processing the data easier.
In general splitting data up makes it harder to work with.
Steven Lord
Steven Lord 2018 年 10 月 26 日
I second Stephen's comment. If you had a table with 1000 unique company names, do you really want to create 1000 individual variables in the workspace? That's highly discouraged.
In addition to splitapply and findgroups which Stephen mentioned, there are functions like groupsummary (introduced in release R2018a) and grouptransform (introduced in release R2018b) that may make your workflow with the one larger table easier.
Perhaps if you tell us more about how you're planning to use those small company-specific table arrays we can offer suggestions for how to achieve your goal without creating lots of individual variables.

サインインしてコメントする。

回答 (1 件)

madhan ravi
madhan ravi 2018 年 10 月 26 日
編集済み: madhan ravi 2018 年 10 月 26 日
LastName = {'Smith';'Johnson';'William';'William1';'Smith1'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];
T = table(Age,Height,Weight,BloodPressure,...,
'RowNames', LastName)
smith = T('Smith',:) %creates new table for smith
johnson = T('Johnson',:) %creates new table for Johnson
william = T('William',:) %creates new table for William
COMMAND WINDOW DISPLAYS:
T =
5×4 table
Age Height Weight BloodPressure
___ ______ ______ _____________
Smith 38 71 176 124 93
Johnson 43 69 163 109 77
William 38 64 131 125 83
William1 40 67 133 117 75
Smith1 49 64 119 122 80
smith =
1×4 table
Age Height Weight BloodPressure
___ ______ ______ _____________
Smith 38 71 176 124 93
johnson =
1×4 table
Age Height Weight BloodPressure
___ ______ ______ _____________
Johnson 43 69 163 109 77
william =
1×4 table
Age Height Weight BloodPressure
___ ______ ______ _____________
William 38 64 131 125 83
>>
  6 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 26 日
編集済み: madhan ravi 2018 年 10 月 26 日
mind uploading the excel file with few datas to maniupulate , have to find another way otherwise it's a huge pain
Peter Perkins
Peter Perkins 2018 年 10 月 31 日
Do a strcmp on the table variable containing the names, and use the logical vector from that as a row subscript on the original table.
But you should considered heeding Stephen and Steve's advice

サインインしてコメントする。

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by