Segmenting a vector into multiple vectors based on the time stamps

10 次查看(过去 30 天)
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

采纳的回答

Turlough Hughes
Turlough Hughes 2019-12-2
编辑:Turlough Hughes 2019-12-2
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by