Setting up time and date

3 vues (au cours des 30 derniers jours)
Maaz Madha
Maaz Madha le 20 Jan 2021
Commenté : Cris LaPierre le 20 Jan 2021
Hi
I'm trying to set up a date and time where it reads from 1:00 today(as in today the time function not today today) till 00:30 tomorrow in consecutives of 30 minutes(half an hour).
%%To determine low load hours and high load hours for valley filling%%
clc
clear
example=xlsread('demand.xlsx');
load=example(:,1);
% t1.Format=('today,1:00')
% t2.Format=('tomorrow,00:30')
datetime.InputFormat('default','yyyy-MM-dd hh:mm:ss') %idk how to do this sorry
t1 = datetime('today,1:00:00');
t2 = datetime('tomorrow,00:30:00');
% t1 = datetime(2020,1,1,1,0,0);
% t2 = datetime(2020,1,2,00,30,0);
%t=t1.Format:hours(0.5):t2.Format;
datetime1=datenum(t);%convert it into strings
ts=datetime1*24*60*60;
ts1=zeros(48,1);%preallocation k1=zeros(48,1);
ts2=zeros(48,1);
figure(1)
b=plot(ts,load)
% figure(1)
% a=plot(k,load)%%plotting power with regards to k
delta_y=diff(load);%finding difference between one point from another
delta_x=diff(ts);%difference k
delta_x=delta_x';
slope=delta_y/delta_x;
slope=slope(:,1); %find the gradient of the demand to see where load is
%increasing or decreasing
for k=1:length(slope)
if sign(slope(k))==-1 %%when load is decreasing
d(k)=(slope(k));
if d(k)~=0%removing all the zeros
ts1(k)=(k);%gets the indices
end
else %%when load is increasing
e(k)=(slope(k));
if e(k)~=0%removing all the zeros
ts2(k)=k;%gets the indices for when load is increasing
end
end
end
ts1=nonzeros(ts1');%time instants
ts2=nonzeros(ts2')
I want to be able to convert the date and time(today and tomorrow with the fixed times) into seconds so it can plot the graph but also be updated everyday so the values stay relevant.

Réponse acceptée

Cris LaPierre
Cris LaPierre le 20 Jan 2021
Modifié(e) : Cris LaPierre le 20 Jan 2021
Not sure I fully understand, but try this for setting up you time vector.
tVec = today('datetime')+hours(13:.5:24.5)'
tVec = 24×1 datetime array
20-Jan-2021 13:00:00 20-Jan-2021 13:30:00 20-Jan-2021 14:00:00 20-Jan-2021 14:30:00 20-Jan-2021 15:00:00 20-Jan-2021 15:30:00 20-Jan-2021 16:00:00 20-Jan-2021 16:30:00 20-Jan-2021 17:00:00 20-Jan-2021 17:30:00 20-Jan-2021 18:00:00 20-Jan-2021 18:30:00 20-Jan-2021 19:00:00 20-Jan-2021 19:30:00 20-Jan-2021 20:00:00 20-Jan-2021 20:30:00 20-Jan-2021 21:00:00 20-Jan-2021 21:30:00 20-Jan-2021 22:00:00 20-Jan-2021 22:30:00 20-Jan-2021 23:00:00 20-Jan-2021 23:30:00 21-Jan-2021 00:00:00 21-Jan-2021 00:30:00
  2 commentaires
Maaz Madha
Maaz Madha le 20 Jan 2021
I think its meant to be datetime('today') because that worked for me but your answer was very helpful. Thank you
Cris LaPierre
Cris LaPierre le 20 Jan 2021
Either works. When in doubt, you can aloways consult the documentation.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by