Filter löschen
Filter löschen

DATE LOOPS AND DATE TRATEMENT IN MATLAB

4 Ansichten (letzte 30 Tage)
André Bernal García
André Bernal García am 28 Mär. 2017
Im working with quite a lot of data and I want to use it in a Matlab code.
The data is identified for a certain time and and hour with a certain timestamp ( given as a number)
I want to create loops that are using the DATA especified for that certain timestamp.
I was trying to do so by generating a datetime array in matlab, as the following picture shows:
But when I am trying to do a loop such as:
for i=TIMED(1):TIMED(8774) X= UP(i)/1000 Y=Eoffered (i)*UP(i)
I have the following error:
Function 'subsindex' is not defined for values of class 'datetime'.
Error in ASS2 (line 15) Pelspot(TIMED)=ELSPOT(TIMED)/1000; % €/ kW
PS: I will have to use a lot of data and it is not always in order ( some values are repeated) so I want to get sure that only the values with that timestamp are used.
Thanks in advance !! =)
I have the data in an excel file, I dont know how to create a database but maybe is useful.

Antworten (1)

Steven Lord
Steven Lord am 28 Mär. 2017
What is the "December 31st, 2015 at 10 AM"-th element of the vector [15.86; 17.79; 18; 18.84; 19; ...]? Does that question even make sense?
If you're using release R2016b or later, store your data in a timetable. Since dates and times are an integral part of a timetable, you can index into a timetable using dates and times.
  1 Kommentar
André Bernal García
André Bernal García am 28 Mär. 2017
Bearbeitet: André Bernal García am 28 Mär. 2017
Maybe I wrote my question wrong:
I have the data like this in Excel:
--------------------------------------------------
Where the timestamp(number) represents yyyymmddHHMM
To transform the timestamp to date I created an arrow just with the timestamp and I did:
%TIME is the vector in column with the timestamps
str = num2str(TIME, '%11d');
dn = datenum(str, 'yyyymmddHHMM');
ds = datestr(dn, 'yyyy-mm-dd HH:MM') % ‘Legacy’ Functions
dt = datetime(str, 'InputFormat','yyyyMMddHHmm', 'Format','yyyy-MM-dd HH:mm') % ‘datetime’ Function
Now, as you told me I am trying to create a timetable but: - If I use the excel table directly then it does not recognizes time.
-I have not been able to change the first column to a "date" column and therefore the timetable comand does not accept it as a timecolumn and it does not work

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Time Series Objects finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by