Indexing to return segments
Show older comments
Hi. I know this could look like a silly question but can't find a way to do it. I have a matrix (data) that is 14258 x 7, the first six columns are data from a subject and the last column are time markers (0 off and 5 is on).
I used ischange on the last column to have the changing points:
[index,~] = ischange(data(:,7))
The problem is that I should end with 10 segments (of different duration) that include the data of the other 6 columns, but I don't know how to use the index to have it.
Thanks in advance
Accepted Answer
More Answers (1)
Bob Thompson
on 29 Jan 2021
It looks like the index output is actually a logic array. I recommend using find to identify the actual indexes of the identified changes. I imagine it woud look something like the following, but it is untested:
[index] = find(ischange(data(:,7))==1);
I'm not quite sure how you want to utilize the different sections, but you could capture the different time elements in a cell array kind of like the following:
timedata{1} = data(1:index(1)-1,1:6);
for i = 1:length(index)-1
timedata{i+1} = data(index(i):index(i-1),1:6);
end
timedata{length(index)+1} = data(index(end):end,1:6);
1 Comment
Frank Pernett
on 9 Mar 2021
Categories
Find more on Timing and presenting 2D and 3D stimuli in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!