Append to vector of different sizes in for loop
12 views (last 30 days)
How does one append a vector to a another vector within a loop.
I have the code below: Point is i want the signal between the first and second indices of ipts. then the third and fourth et cetera up to the nineteenth to twentieth.
with this code I only get the last part nineteenth to twentieth.
i = 1;
while i < 19;
A = TimeSeries_short(ipts(i):ipts(i+1));
i = i+2;
.mat file is attached.
More Answers (1)
dpb on 14 Feb 2021
The short answer is
i = 1;
A = [A;TimeSeries_short(ipts(i):ipts(i+1),:);
Normally one frowns on dynamic reallocation, but presuming the overall array is going to be relatively small, the time taken won't be excessive.
If A is going to be very large, then one will want to calculate the final size and compute the indices going in and explicitly set the rows.