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
2 个评论
Turlough Hughes
2019-12-2
Could you upload the two variables as a .mat perhaps or provide code to replicate the data?
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File 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!