How can I break up a large table by one of its columns?
1 view (last 30 days)
Show older comments
I have a large MatLab table that I am trying to divide into several smaller tables based on one of it's columns.
The table looks a bit like this:
'Collection Method' 'Location Name' 'Date' 'Measurement'
{'Sensor A' } { 'City A' } 18-May-2016 12.4
{'Sensor A'} { 'City B'} 19-May-2016 17.1
{'Sensor B'} {'City A'} 19-May-2016 13.2
How to I take everything with Location Name 'City A' and put it into a new table?
0 Comments
Answers (2)
Walter Roberson
on 21 Jan 2024
CityA_Table = YourTable(YourTable.('Location Name') == "City A", :);
If you want to break down by location then
G = findgroups(YourTable.('Location Name'));
fun = @(varargin){cell2table(varargin, 'VariableNames', YourTable.Properties.VariableNames)};
SplitTable = splitapply(fun, YourTable, G);
0 Comments
Steven Lord
on 21 Jan 2024
Do you need to create an arbitrary number of variables or do you need to perform some sort of calculation on each set of rows that have the same value in the Location Name variable? If the latter, use the functions in the Grouping and Binning Data category on this documentation page like groupsummary, grouptransform, or splitapply rather than creating lots of individual variables.
0 Comments
See Also
Categories
Find more on Data Type Identification in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!