0
votes

I have several vectors I would like to concatenate, where each element is an increasing timestamp, but how do I concatenate the vectors while ensuring to have an continuously time scale?

Say, I have two vectors tone1_time and tone2_time both given by 1x4801 double. Each element of the vector contain a timestamps and thus the elements must be added when the vectors are concatenated in order to have the correct time. So far I have;

n = 10;

for i = 1:n
    time(n,end) = tone1_time + tone2_time;
end

Which generates an error in matlab!

EDIT: More code

I generate two sounds vectors and concatenate them by:

% repeat n times
n = 10;

signal = [ tone1_signal tone2_signal ];

signal = repmat(signal,1,n);

This will e.g. return a new vector signal with a length of e.g. 1x48020 double. The time vector needs to have the same size as this vector, but also still having an continuously time.

1

1 Answers

1
votes

first, you need to add the last element of tone1_time to all elements of tone2_time to ensure continuity of the time intervals:

tone2_time = tone2_time + tone1_time(end);

Then you can concat them

tone_time = [tone1_time, tone2_time];

Alternatively, you can work with the differences

tone_time = cumsum([diff([0 tone1_time]), diff([0 tone2_time])]);

EDIT:
For replicating the time vector:

tone_time_diff = [diff([0 tone1_time]), diff([0 tone2_time])];
tone_time = cumsum( repmat(tone_time_diff, 1, n) );