Expand an array by filling in with current values in MATLAB -


i have simple issue , want know if there's easy way in matlab (i.e. function rather writing out loops or myself).

let's have timeseries time 1:1:1000 , data 2 * (1:1:1000) , want expand array making time , data vector finer. let's want time 1:0.1:1000 , data 2 * (1:0.1:1000). there easy way tell matlab repeat values of each vector 10 times (from 1 / 0.1 = 10) can have this?:

time: [1, 2, 3, 4, ...]

data: [2, 4, 6, 8, ...]

to:

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

you can use combination of reshape() , repmat() follow:

data = [2, 4, 6, 8, ...] % stated in question.  data = reshape(repmat(data, 10, 1), 1, []); 

this more time-efficient others kron() or combination of sort() , repmat().

two simulations done , results shown in following figures.

first: simulation time vs. length of data. here used n=100 instead of 10.

enter image description here

second: simulation time vs. repetition factor. length of data 10000.

enter image description here

so can select best 1 according simulation results.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -