Segmenting a vector into multiple vectors based on the time stamps
11 views (last 30 days)
Show older comments
Masahiro Yamada
on 2 Dec 2019
Commented: Masahiro Yamada
on 2 Dec 2019
Hi,
I have a vector of data [3000 1] and another vector that shows events (time stamps). I'd like to split the vector into multiple segments based on the time stamps (from point 1 to 2, from 2 to 3, from 3 to 4...and so on). The events are not equal length. I tried to work on it on my own, but it didn't work. Can someone help me with this?
for j = 1:length(v)-1;
b = v(hit_idx(j):hit_idx(j+1));
Vs = mat2cell(v,b);
end
2 Comments
Turlough Hughes
on 2 Dec 2019
Could you upload the two variables as a .mat perhaps or provide code to replicate the data?
Accepted Answer
Turlough Hughes
on 2 Dec 2019
Edited: Turlough Hughes
on 2 Dec 2019
Hey Masahiro,
As I understand it, you have a column vector a_Y, and a second vector hit_idx which provides indices for each segement, where a given segment is a_Y(hit_idx(c):hit_idx(c+1)), c being the count in a loop. To deal with the different lengths I store the segments in cell array as follows:
load('Event.mat')
load('v.mat')
Data = cell(length(hit_idx)-1,1);
for c = 1:length(hit_idx)-1
Data{c,1} = a_Y(hit_idx(c):hit_idx(c+1));
end
More Answers (0)
See Also
Categories
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!