Split one table into multiple tables based on multiple variables without reordering.

조회 수: 32 (최근 30일)
I have imported a large csv file into matlab as a table with aggregate data from a number of sensors. The first column denotes the sensor group 9716 or 9718. The second column denotes the the sensor ID within the sensor group. Some sensor numbers are repeated in the two sensor groups. I would like to split the data into tables based on the unique combinations of node and input. For example one table would include all readings of input 5 from node 9716. Node and input are column names in the csv file. Is this something that I can do in MATLAB?
I have only included the first 600 rows of this csv file in the attachment for simplicity.

채택된 답변

Matt J
Matt J 2023년 1월 30일
편집: Matt J 2023년 1월 30일
T=readtable('Data - 2023-01-26_question');
G=findgroups(T(:,1:2));
I=(1:numel(G))';
splitTables = splitapply(@(i){T(i,:)},I,G)
splitTables = 14×1 cell array
{58×6 table} {58×6 table} {58×6 table} {58×6 table} {58×6 table} {57×6 table} {57×6 table} {57×6 table} {23×6 table} {23×6 table} {23×6 table} {23×6 table} {23×6 table} {23×6 table}
  댓글 수: 2
Aaron DeSantis
Aaron DeSantis 2023년 1월 30일
Thank you for the fast reply. I do not have a coding background so can you explain the function within the splitapply?
Matt J
Matt J 2023년 1월 30일
편집: Matt J 2023년 1월 30일
You are welcome, but please Accept-click the naswer if it does what you want.
The function that is the first argument to splitapply selects the rows of the table T corresponding to a single group and puts them in their own separate table, and this subtable is then placed in a cell {}.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by