MATLAB: Repeat data set only in certain indices

repmat

Hello all, I have a data set that represents the movement of an object over time. The data is a matrix of size (x,5) when x varies. However, the time stamps are non consecutive, for example: time = [0;9.5;23.1;52.26;….;last time point]. I want to make the data set the same size as the last time point, with repeating values where the time is non consecutive, like so:
data = [300 200 0 3 3.2; 201 300 4 3 2.8]
new_data = [300 200 0 3 3.2 ; 300 200 1 3 3.2 ; 300 200 2 3 3.2 ; 300 200 3 3 3.2 ; 201 300 4 3 2.8]
(the third column is the time points). I tried something like this:
total_time = 0:Data(end,3);
new_data = nan(length(total_time),5);
for i = 1:length(Data)
if round(Data(i,3),0) ~= total_time(i)
new_data(i,:) = repmat(Data(i,:),1);
else
new_data(i,:) = Data(i,:);
end
end
But this does not seem to work, any ideas why?

Best Answer

[repmat(data(1,:),4,1);data(2,:)]