필터 지우기
필터 지우기

separate table data in to sub tables

조회 수: 16 (최근 30일)
ALDO
ALDO 2019년 4월 19일
댓글: ALDO 2019년 10월 10일
Hi everyone
I have a table of data the size of 10000x3. There are 300 different names used in the rows. I would like to seperte the variables that have the same name and make a tabel for each variable.
for example if the table below is my original table :
name Variable1 variable2 variable3
A variable1_A1 variable2_A2 variable3_A3
B variable1_B1 variable2_B2 variable3_B3
K variable1_K1 variable2_K2 variable3_K3
L variable1_L1 variable2_L2 variable3_L3
A variable1_A4 variable2_A5 variable3_A6
A variable1_A7 variable2_A8 variable3_A9
L variable1_L4 variable2_L5 variable3_L6
I need to devide it to 4 differnt tables (one for each name):
name Variable1 variable2 variable3
A variable1_A1 variable2_A2 variable3_A3
A variable1_A4 variable2_A5 variable3_A6
A variable1_A7 variable2_A8 variable3_A9
name Variable1 variable2 variable3
L variable1_L1 variable2_L2 variable3_L3
L variable1_L4 variable2_L5 variable3_L6
Thank you in advance for your help!

채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 19일
편집: Walter Roberson 2019년 4월 19일
G = findgroups(YourTable.name);
output = splitapply(@(varargin) {table(varargin{:}, 'VariableNames', YourTable.Properties.VariableNames)}, YourTable, G);
This should give a cell array of tables.
  댓글 수: 3
Walter Roberson
Walter Roberson 2019년 4월 20일
I edited the code while you were reading my earlier response.
The c* variable stood in for columns as the documentation implies that the parameters need to be individual variables, but I figured out the way to code around that.
ALDO
ALDO 2019년 4월 23일
Thank you for taking the time to look over it

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Peter Perkins
Peter Perkins 2019년 5월 3일
ALDO, unless you have a good reason for wanting to do this, I'm gonna suggest that you consider NOT doing it. There are a bunch of functions in MATLAB that are happy to do "grouped" calculations on your original timetable, and you will likely find those easier to use than having to loop over a 300-element cell array of tables.
  댓글 수: 1
ALDO
ALDO 2019년 10월 10일
Thank you for your sugestion

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by