split table in mat lab with respect to row values

26 visualizaciones (últimos 30 días)
wissam abdallah
wissam abdallah el 17 de Feb. de 2018
Editada: Rena Berman el 16 de Jul. de 2024
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

Respuestas (1)

Peter Perkins
Peter Perkins el 17 de Feb. de 2018
Editada: Rena Berman el 16 de Jul. de 2024
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 comentarios
Imola Fodor
Imola Fodor el 4 de Ag. de 2021
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 el 6 de Ag. de 2021
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by