How to repeat sample data in minutes?

5 views (last 30 days)
fatin anuwar
fatin anuwar on 20 Mar 2018
Edited: Andrei Bobrov on 22 Mar 2018
I have 24 hours data sampled in every 5 minutes (using data logger interval every 5 minutes). how i want to repeat my data in every minutes for 24 hours(since my data every 5 minutes).i want to do simulation every 1 minutes for 24 hours.
I'm using matlab 2015.
my example:
%%Import input from actual data
%%import excel data
irr_2016_jan_1 = xlsread('data_2016.xlsx','Jan','CF9:CF296'); % Import data from day 1 january
irr_2016_jan_1 =irr_2016_jan_1'; % transpose data
%%convert data to every minute daily
irr = zeros(1,1381); % create array of zeros for time
for i=1:1:1381
irr(i+5)= irr_2016_jan_1(j)
end
- i try to do it but im stuck here. i need help plz...thanks
  1 Comment
Guillaume
Guillaume on 20 Mar 2018
Edited: Guillaume on 20 Mar 2018
How is the data in the 4 missing minutes supposed to be generated? Just replicating the 1st minute, or do you want to interpolate?
What is the reason for inventing more data?
Which version of matlab are you using? Have you considered using a timetable. Whatever you want to do would be trivially done with the retime function of a timetable. edit: refer to Andrei's answer to see how easy it is with timetables

Sign in to comment.

Answers (2)

Andrei Bobrov
Andrei Bobrov on 20 Mar 2018
Edited: Andrei Bobrov on 22 Mar 2018
data = randi(456,288,1); % your data
time = minutes(5:5:1440)';% time of your data
T = timetable(time,data,'v',{'data'});
Tout = retime(T,minutes(0:1440)','linear');
or
last row of code:
Tout = retime(T,minutes(0:1440)','next');
ADDED [MATLAB R2015]
data = randi(456,288,1); % your data
time1 = (5:5:1440)';
time2 = (1:1440)';
F = griddedInterpolant(time1,data,'linear','linear');
T_out = array2table([time2, F(time2)],'v',{'Time','Data'});
or
ii = (1:1440)';
idx = ceil(ii/5);
time2 = (1:1440)';
T_out2 = array2table([time2,data(idx)],'v',{'Time','Data'});

KL
KL on 20 Mar 2018
Your variable name looks like you're working with irradiation, in that case I wouldn'r recommend interpolation for your simulation. You should rather get data with 1-minute resolution. If you simply want to repeat the same value 5 times, here is an example,
%create a dummy variable A
>> A = (1:5).'
A =
1
2
3
4
5
%now do the repmat and reshape
>> AA = reshape(repmat(A,1,5).',[],1)
AA =
1
1
1
1
1
2
2
2
2
2
3
3
3
...
  2 Comments
Guillaume
Guillaume on 20 Mar 2018
Since R2015a, you have repelem that makes it easier:
AA = repelem(A, 5)
KL
KL on 20 Mar 2018
Thanks Guillaume, I didn't know this.

Sign in to comment.

Categories

Find more on Timetables in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!