Expand the array by filling in the current values in MATLAB
I have a pretty simple problem and I just want to know if there is an easy way to do this in MATLAB (i.e. a function to do this, not to write loops or whatever).
Let's say I have timers where Time 1:1:1000
and Data are 2 * (1:1:1000)
and I want to expand the array making the time and data more precise. Let's say that I want time to be 1:0.1:1000
and Data to be 2 * (1:0.1:1000)
. Is there an easy way to tell MATLAB to repeat the values of each vector 10
once (from 1 / 0.1 = 10
) so that I can have something like this ?:
Time: [1, 2, 3, 4, ...]
Data: [2, 4, 6, 8, ...]
in
Time: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, ...]
Data: [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, ...]
source to share
You can use a combination of reshape()
and repmat()
like this:
Data = [2, 4, 6, 8, ...] % As stated in the question.
Data = reshape(repmat(Data, 10, 1), 1, []);
It is more economical than others such as kron()
or a combination of sort()
and repmat()
.
Two simulations were run and the results are shown in the following figures.
First: simulation time versus length Data
. Here I used N = 100 instead of 10.
Second: simulation time and repetition rate. The length Data
is 10,000.
So you can choose the best one according to the simulation results.
source to share