split table in mat lab with respect to row values

26 ビュー (過去 30 日間)
wissam abdallah
wissam abdallah 2018 年 2 月 17 日
編集済み: Rena Berman 2024 年 7 月 16 日
Hi i try to write script in matlab so as i can split my table in many others tables. my script return an error mentioned in the following picture which also clarify all my workspace and the description of my table(climSumry):
any one can help me to find where is the error in my script and how i should correct it ?? thank you. Regards

回答 (1 件)

Peter Perkins
Peter Perkins 2018 年 2 月 17 日
編集済み: Rena Berman 2024 年 7 月 16 日
It's hard to know what you are trying to do, but I'm guessing you want to split up a table, by rows, based on one of the variables in the table. It looks like maybe you have two groups of rows.
I really recommend you take a look at the documentation for tables, including the section on subscripting, but to answer your question,
>> t = table(["a";"a";"a";"b";"b"],rand(5,1),rand(5,1))
t =
5×3 table
Var1 Var2 Var3
____ _______ _______
"a" 0.26187 0.10676
"a" 0.33536 0.65376
"a" 0.67973 0.49417
"b" 0.13655 0.77905
"b" 0.72123 0.71504
>> ta = t(t.Var1=="a",2:3)
ta =
3×2 table
Var2 Var3
_______ _______
0.26187 0.10676
0.33536 0.65376
0.67973 0.49417
>> tb = t(t.Var1=="b",2:3)
tb =
2×2 table
Var2 Var3
_______ _______
0.13655 0.77905
0.72123 0.71504
  2 件のコメント
Imola Fodor
Imola Fodor 2021 年 8 月 4 日
is there an programatic way to do this? i have a lot of groups, and they are actually compound on 3 different columns
Peter Perkins
Peter Perkins 2021 年 8 月 6 日
Here's one way: use findgroups to identify the groups in your table. Loop from 1:numGroups, and use something like
tables{i} = t(grp == i,2:3)
to put each subtable in a cell array.
BUT: I'm gonna suggest that you probably don't want to do that. Most of the things that you would do on those individual tables in the cell array can be done using groupsummary, groupfilter, grouptransform, rowfun, or maybe others.

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

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by