Segmenting a vector into multiple vectors based on the time stamps

조회 수: 15 (최근 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
Turlough Hughes 2019년 12월 2일
Could you upload the two variables as a .mat perhaps or provide code to replicate the data?
Masahiro Yamada
Masahiro Yamada 2019년 12월 2일
Sorry, added the files to the original post. Thanks for helping me!

댓글을 달려면 로그인하십시오.

채택된 답변

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