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

3 vues (au cours des 30 derniers jours)
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 commentaire
Bob Thompson
Bob Thompson le 7 Mai 2018
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.)

Connectez-vous pour commenter.

Réponse acceptée

Ameer Hamza
Ameer Hamza le 7 Mai 2018
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 commentaires
Centauri Jolene
Centauri Jolene le 8 Mai 2018
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 le 8 Mai 2018
You are welcome.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by