How can I break up a large table by one of its columns?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Walter Roberson
am 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 Kommentare
Steven Lord
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!