How to repeat sample data in minutes?

조회 수: 5 (최근 30일)
fatin anuwar
fatin anuwar 2018년 3월 20일
편집: Andrei Bobrov 2018년 3월 22일
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
Guillaume
Guillaume 2018년 3월 20일
편집: Guillaume 2018년 3월 20일
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

댓글을 달려면 로그인하십시오.

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2018년 3월 20일
편집: Andrei Bobrov 2018년 3월 22일
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 2018년 3월 20일
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
Guillaume
Guillaume 2018년 3월 20일
Since R2015a, you have repelem that makes it easier:
AA = repelem(A, 5)
KL
KL 2018년 3월 20일
Thanks Guillaume, I didn't know this.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Timetables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by