how can I separate data per group ID

3 visualizaciones (últimos 30 días)
Galina Machavariani
Galina Machavariani el 20 de En. de 2020
Comentada: Guillaume el 20 de En. de 2020
Hello,
I have a csv data file containing a column with group ID (string), and a column with measured data .
(For each group, there are many measurements).
I want to separate & process the data per group, extracting & processing vector of measured data for each group
The problem is that the number of measurements per group is different for different groups, so I can not apply cycle.
Is it possible to separate data per group , by reading the group ID and creating data vector for each group ID ? Thank you !
  2 comentarios
Bhaskar R
Bhaskar R el 20 de En. de 2020
Editada: Bhaskar R el 20 de En. de 2020
Can you share your file as a sample?
Stephen23
Stephen23 el 20 de En. de 2020
"The problem is that the number of measurements per group is different for different groups, so I can not apply cycle."
I don't see any reaons why that would be the case, a simple loop with indexing would work fine, as would any of the more recent tools for handling groups of data:

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 20 de En. de 2020
Editada: Guillaume el 20 de En. de 2020
The fact that you don't have the same number of samples per group should not be a problem. As Stephen commented, this wouldn't prevent you from using a loop.
However, as Stephen also said, matlab has plenty of tools designed just for this sort of processing. The exact tool to use depends on what exactly you want to do, and you haven't said. It could be something as simple as:
measurements = readtable('C:\somewhere\yourfile.csv');
%I'm assuming your file has headers and one of them is ID
IDmean = groupsummary(measurement, 'ID', 'mean'); %get the mean of each signal per ID
  2 comentarios
Galina Machavariani
Galina Machavariani el 20 de En. de 2020
Thank you very much, Guillaume
I earlier used "csvread " command, and did not know about "groupsummary"
I tried groupsummary, but here is what I obtain:
"Warning: Variable names were modified to make them valid MATLAB identifiers. The original names are saved in the VariableDescriptions property. "
How to overcome this ? Thanks !!!
Guillaume
Guillaume el 20 de En. de 2020
This warning comes from readtable not from groupsummary. Additionally, it is just a warning, it may not be a problem. However, if you're on R2019b or later, you can get rid of it with:
measurements = readtable('yourfile', 'PreserveVariableNames', true);
In earlier versions, you can't do that. Best you can do is rename the variables to whatever you want if you don't like the names matlab autogenerate.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by