MATLAB Answers

Filter a structure by a value of a field

47 views (last 30 days)
PAK on 3 Aug 2018
Answered: Bob Nbob on 6 Aug 2018
Hi All,
I have data in the following structure called "recEv".
I would like to find the values of another matrix called cluster_class(size: n x 2) that fall between the first and last eegoffset number corresponding to each unique list value. So, for example, I would like to find the values in the cluster class matrix that fall between (225035 - 228285), (323831 - 327527), (424105 - 429244), (531709 - 533974) etc. I would like my output matrix to stay the size (n x 2).
I've tried putting the unique list values into a variable and looping through recEv, however I have been largely unsuccessful. Any help would be much appreciated!!
Thank you,


Jan on 4 Aug 2018
Please post some relevant inputs. It is not clear if this is a struct array or a scalar struct containing vectors. You did not mention, what the data of the matrix cluster_class are and what you want as output exactly.
PAK on 6 Aug 2018
Hi Jan,
"recEV" is a 1 x 97 struct with 18 fields. Cluster_class is a double 21464x2 matrix (where the first column is spike times and the second column denotes the cluster class). I've posted a picture of that one below.
Essentially, I'd like to use the field 'list' and 'eegoffset' to search through the first column of the cluster_class matrix and return spikeTimes and cluster classes that fall between the bounds of the first and last event in each list.
For example, the first list in "recEV" goes from recEv.eegoffset (225035 - 228285). I'd like to search through the "cluster_class" matrix below and only return values that fall within that time period. And then repeat that process for all of the values in "recEv.list". The output would be the same as cluster_class, it just would be filtered for my time periods of interest.
Thanks much for your help!

Sign in to comment.

Answers (1)

Bob Nbob
Bob Nbob on 6 Aug 2018
Hmmm, just gonna wing it and see if this is correct.
for k = 1:max(recEV(:).list);
special = cluster_class(cluster_class(:,2)>=min(recEV(:).eegoffset(recEV(:).list==k))&cluster_class(:,2)<=max(recEV(:).eegoffset(recEV(:).list==k)),:);
Basically, it just loops through each value of list and attempts to use logic indexing to leave you with cluster_class rows which have a second value that falls within the range of eegoffset. Probably won't work first try, but thought it was kind of fun to make.


Sign in to comment.




Community Treasure Hunt

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

Start Hunting!