Cells merging in table

8 views (last 30 days)
Eduard Mazur
Eduard Mazur on 16 Aug 2019
Answered: Guillaume on 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

Accepted Answer

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

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!