MATLAB Answers

Creating n number of tables using already present table in matlab

22 views (last 30 days)
Sanket Gaikwad
Sanket Gaikwad on 9 Dec 2020
Answered: Eric Sofen on 14 Dec 2020
I'm trying to create n number of tables based on a main table that I have. I want to create this micro tables on column conditions from main table.
First micro table will be between adjacent 0 speed(column) and odometer(first to last of micro table) condition of greater than 0km.
I want to generated yellow tables as shown in attachment.

Answers (2)

Nitin Kapgate
Nitin Kapgate on 14 Dec 2020
You can refer to the following code snippet to learn about extracting sub-tables based on conditions on the data in columns of main table:
% Create a table by reading all columns from the file, patients.dat.
T = readtable('patients.dat');
T(1:5,:)
% View the data type, description, units, and other descriptive statistics
% for each variable by creating a table summary using the summary function.
summary(T) % A table with 100 rows
% Get a sub-table based on conditions on columns
T_New = T((T.Height > 67) & (T.Weight > 142.5), :);
summary(T_New) % A sub-table with 40 rows
Refer the link to learn more about tables.

Eric Sofen
Eric Sofen on 14 Dec 2020
I would advise that in many cases, you're better off adding a grouping variable based on the conditions you described and doing grouped calculations (using groupsummary, varfun, or findgroups/splitapply) rather than splitting your table into a bunch of separate workspace variables. Once you've got a bunch of subtables with different names in your workspace, they become hard to iterate over compared to one table with a grouping variable.

Products

Community Treasure Hunt

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

Start Hunting!