Using date and time in MATLAB

9 vues (au cours des 30 derniers jours)
Adnan Jayyousi
Adnan Jayyousi le 19 Juin 2022
Commenté : Peter Perkins le 21 Juin 2022
Hello everyone,
I used to make this kind of work with excel, but I was suffering excel limitations last months and I think MATLAB is more friendly for me because I've some previous experience with it, and because of the flexibility to change things without 10 meters long formulas :)
So, I've two excel sheets, one sheet contains the electricity tariff in my country, the tariff is dynamic i.e. it changes depending on the seasons, hours, days, and holidays.
I want to import the sheet that called "LoadProfile&Tariff" to MATLAB, then I want matlab to fill the "Tariff" column (now it's empty).
The "TOU - 2023" sheet contains the data of tariffs and the corresponding seasons and times, the tariff is divided into two modes, "Off peak" and "On Peak"
The off peak is lowest price at a given season.
The on peak is the highest price on a given season.
I've explored the internet for some examples without success, I would appreciate any example for applying some logics on dates, i.e. statements like "if" / "for" etc..
Any suggestions ?
Thanks in advance.

Réponse acceptée

Peter Perkins
Peter Perkins le 20 Juin 2022
I'm having trouble following exactly what needs to be done, but I imagine you want to append variables to your LoadProfile&Tariff timetable (you are going to make it a timetable, right?) to specify season and on/off-peak for each timestamp. Then you can use a join to add the tariffs from a table with season and on/off-peak values. Not sure how everything is defined, seasons by month, on/off-peak by, don't know, time of day, day of week, holidays? datetime has all kinds of comparisons that will handle all that.
  2 commentaires
Adnan Jayyousi
Adnan Jayyousi le 20 Juin 2022
Hi Peter,
Thanks for your reply,
Well, Not exactly, it's more simple.
I want to make timetable - yes, but i don't want to import the tariff from another table, the sheet called "TOU - 2023" is only made to describe the hours and the range of the days for each tariff, it's not made for importing.
the only sheet that will be imported to MATLAB is the "LoadProfile&Tariff", this table will be imported empty and will contain only the time array (Column A in excel).
The main issue (in my point of view) is to find a syntax that can return a certain day, month or hour.
For example : the logic, in words, should be like this :
"If the day is in between sunday and thursday & it's not a holidaay & the hours is between 8:00 - 12:00 & the season is #1" so put the tariff X into tariffs column.
how can I implement this logic as a code ?
thanks
Peter Perkins
Peter Perkins le 21 Juin 2022
That's pretty simple logic, easily implemented using datetimes. relational comparisons, isbetween, timeofday, etc.
I disagree that this is not a join operation. This: "so put the tariff X into tariffs column" absolutely is a join.

Connectez-vous pour commenter.

Plus de réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 19 Juin 2022
(1) Import data into MATLAB:
DB = readtable('YOUR_MS_Excel_Data.xlsx', 'Sheet', 'LoadProfile&Tariff', 'Range','A2:B38');
(2) Create a logical array to identify which time is on-peak and which one if off-peak, e.g.
IND= find(DB.Var1>'1/1/2020 8:15:00'); % Check your imported data's time format and match with it
(3) Create another column in DB table specifying "on-peak" and "off-peak"
...
  1 commentaire
Adnan Jayyousi
Adnan Jayyousi le 19 Juin 2022
Hi Sulaymon,
Thanks for your reply,
about (2), I see that you used " > " greater than statement, I think it may make it complicated because on&off peak times change according the season,
I've thinked about statements like this one for example :
If in column A the season is #1(DECEMBER/JANUARY/FEB) & the hour is 8:00 & it's not a weekend --> so tariff is 0.2307.
Thanks

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by