Segmenting a vector into multiple vectors based on the time stamps

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 commentaires

Could you upload the two variables as a .mat perhaps or provide code to replicate the data?
Sorry, added the files to the original post. Thanks for helping me!

Connectez-vous pour commenter.

 Réponse acceptée

Turlough Hughes
Turlough Hughes le 2 Déc 2019
Modifié(e) : Turlough Hughes le 2 Déc 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
You may find the numerous links here to be useful.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by