how can I separate data per group ID

3 vues (au cours des 30 derniers jours)
Galina Machavariani
Galina Machavariani le 20 Jan 2020
Commenté : Guillaume le 20 Jan 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 commentaires
Bhaskar R
Bhaskar R le 20 Jan 2020
Modifié(e) : Bhaskar R le 20 Jan 2020
Can you share your file as a sample?
Stephen23
Stephen23 le 20 Jan 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:

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 20 Jan 2020
Modifié(e) : Guillaume le 20 Jan 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 commentaires
Galina Machavariani
Galina Machavariani le 20 Jan 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 le 20 Jan 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by