Cells merging in table

8 Ansichten (letzte 30 Tage)
Eduard Mazur
Eduard Mazur am 16 Aug. 2019
Beantwortet: Guillaume am 16 Aug. 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

Akzeptierte Antwort

Guillaume
Guillaume am 16 Aug. 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))

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by