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

1 次查看(过去 30 天)
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, :);

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by