MATLAB: Cells merging in table

cell arraysMATLABmergeswitchvertcat

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

Best Answer

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))