Will this do:
interval = 2; % 2 hour-interval maxHr = 23; tmstamp = 0 : interval : maxHr; len = length(tmstamp);
Within your loop, add the following loop: A = decomposedTraj(i).dailyScaled(:,5); for index = 2 : len predicate = A >= tmstamp(index-1) & A < tmstamp(index); Interval(i).(sprintf('interval_%d',index-1)) = A(predicate); if index == len Interval(i).(sprintf('interval_%d',index)) = A(A >= tmstamp(end)); end end
Now your code should look like: A. Before the for loop, enter the following lines:
interval = 2; % 2 hour-interval
maxHr = 23;
tmstamp = 0 : interval : maxHr;
len = length(tmstamp);
B. now your loop should be:
% decomposedTraj is a struct that contains the trajectories based on daily scale
for i=1:size(decomposedTraj,2)
if ~isempty(decomposedTraj(i).dailyScaled)
% Get data
A = decomposedTraj(i).dailyScaled(:,5);
% Update the Interval struct array
for index = 2 : len
predicate = A >= tmstamp(index-1) & A < tmstamp(index);
Interval(i).(sprintf('interval_%d',index-1)) = A(predicate);
if index == len
Interval(i).(sprintf('interval_%d',index)) = A(A >= tmstamp(end));
end
end
end
end