how can I separate data per group ID

3 Ansichten (letzte 30 Tage)
Galina Machavariani
Galina Machavariani am 20 Jan. 2020
Kommentiert: Guillaume am 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 Kommentare
Bhaskar R
Bhaskar R am 20 Jan. 2020
Bearbeitet: Bhaskar R am 20 Jan. 2020
Can you share your file as a sample?
Stephen23
Stephen23 am 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:

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Guillaume
Guillaume am 20 Jan. 2020
Bearbeitet: Guillaume am 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 Kommentare
Galina Machavariani
Galina Machavariani am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by