Load in subsets of data from csv file based on multiple column values

1 回表示 (過去 30 日間)
Centauri Jolene
Centauri Jolene 2018 年 5 月 7 日
コメント済み: Ameer Hamza 2018 年 5 月 8 日
I have a csv file for which I need to load in timeseries of data for each member of a pair. The file contains data for activity windows 1 - 6 and for multiple pairs. Each pair is made up of subject (sub) 1 and subject (sub) 2, and contains data for windows 1 through 6.
For each window, I need to load in the data for pair 1 subject 1 and pair 1 subject 2 together. The timeseries are the same length within the same pair, but are different across pairs (from the 'alpha' column). Thus, to use pair 1 window 1 as an example, I need two timeseries: (1) The alpha timeseries corresponding to P01, W1, sub 1 and (2) alpha timeseries corresponding to P01, W1, sub 2
I then need to compute cross correlation on those two timeseries, from which I will extract the max correlation value and the corresponding lag, as well as the correlation value at 0 lag and I can just append these results to a csv file ( I already have code working to do the cross correlation stuff, I just need to figure out how to loop through and load the two appropriate timeseries together).
I am trying to use 'readTable' and 'varfun' to filter the data and apply the function but I am struggling to figure out how to load in the two timeseries together, and then load the two for the next window, etc.. then repeat again for the next pair.
I've attached a preview of the data.
Thank you
  1 件のコメント
Bob Thompson
Bob Thompson 2018 年 5 月 7 日
What about using csvread()? I know it doesn't organize things as prettily as readTable, but sorting through the data just becomes a matter of indexing at that point.
(I did not look at your attached file, sorry, so it may be evident from that file that my question means nothing.)

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

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 7 日
The following lines will split the dataset such that each separated table have same pair, window values and both values for subject,
data = readtable('example.csv');
dataSplit = splitapply(@(x) {cell2table(x, 'VariableNames', data.Properties.VariableNames)}, table2cell(data), findgroups(data(:,[1,4])));
The result is a cell array. Access each separated elements using cell indexing like this: dataSplit{1}, dataSplit{2}, ...
  2 件のコメント
Centauri Jolene
Centauri Jolene 2018 年 5 月 8 日
Awesome this works perfectly and is very simple. Thanks.
I used the following to extract sub 1 and sub 2 from the resulting cells (which contain the data from both subjects):
sub1 = dataSplit{1}(dataSplit{1}.sub==1, :);
Ameer Hamza
Ameer Hamza 2018 年 5 月 8 日
You are welcome.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by