Cells merging in table

조회 수: 10 (최근 30일)
Eduard Mazur
Eduard Mazur 2019년 8월 16일
답변: Guillaume 2019년 8월 16일
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

채택된 답변

Guillaume
Guillaume 2019년 8월 16일
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))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by