How can I break up a large table by one of its columns?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Walter Roberson
el 21 de En. de 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 comentarios
Steven Lord
el 21 de En. de 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 comentarios
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!