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, ...]

+3


source to share


4 answers


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.



enter image description here

Second: simulation time and repetition rate. The length Data

is 10,000.

enter image description here

So you can choose the best one according to the simulation results.

+2


source


As shown in seb, you can use the function repmat

. Here's what I will do:



Data = [2, 4, 6, 8, ...];
Data = sort(repmat(Data,1,10));

      

+1


source


You can use repmat

interval_size = 10;
Data = 2*(1:1:1000);

out_data = repmat(Data,interval_size,1);
out_data = out_data(:)';

      

+1


source


Sample data:

time=1:50
data=2:2:100
t2=1:.1:50.9

      

For time = 1: n it is very simple:

data(:,floor(t2))

      

If your original data has a different timescale, use this:

[a,b]=ismember(floor(t2),time)
data(:,b)

      

0


source







All Articles