how can I separate data per group ID

3 ビュー (過去 30 日間)
Galina Machavariani
Galina Machavariani 2020 年 1 月 20 日
コメント済み: Guillaume 2020 年 1 月 20 日
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 件のコメント
Bhaskar R
Bhaskar R 2020 年 1 月 20 日
編集済み: Bhaskar R 2020 年 1 月 20 日
Can you share your file as a sample?
Stephen23
Stephen23 2020 年 1 月 20 日
"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:

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2020 年 1 月 20 日
編集済み: Guillaume 2020 年 1 月 20 日
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 件のコメント
Galina Machavariani
Galina Machavariani 2020 年 1 月 20 日
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 2020 年 1 月 20 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by