Cells merging in table

7 vues (au cours des 30 derniers jours)
Eduard Mazur
Eduard Mazur le 16 Août 2019
Réponse apportée : Guillaume le 16 Août 2019
Hello
Here is a complex problem:
I need to merge cells inside table (vertcat), by following several rules
There are should be three oiptions inside how to merge
a) by var1: for example if var1=="A" then merge all data after it. (same for var1=="B")
b) by var1 && var2 : for example if var1=="A" && var2=="1" then merge all data (same for all unique variants)
c) by var1 && var2 && var3 : for example if var1=="B" && var2 =="2" && var3=="30" then merge data
I don't know if it's clear, if not please ask question.
Is it possible write same code for all situations?
P.S. I want avoid nested loops, andsomehow create indexes array or something like this

Réponse acceptée

Guillaume
Guillaume le 16 Août 2019
a)
varfun(@(c) {vertcat(c{:})}, table1, 'GroupingVariables', 'Var1', 'InputVariables', 5:width(table1))
b)
varfun(@(c) {vertcat(c{:})}, table1, 'GroupingVariables', {'Var1', 'Var2'}, 'InputVariables', 5:width(table1))
c)
varfun(@(c) {vertcat(c{:})}, table1, 'GroupingVariables', {'Var1', 'Var2', 'Var3'}, 'InputVariables', 5:width(table1))

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by