forked from DeanZeng/electricity_load_forecast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchDBPriceData.m
30 lines (25 loc) · 904 Bytes
/
fetchDBPriceData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function data = fetchDBPriceData(startDate, endDate)
% Set preferences with setdbprefs.
s.DataReturnFormat = 'structure';
s.ErrorHandling = 'store';
s.NullNumberRead = 'NaN';
s.NullNumberWrite = 'NaN';
s.NullStringRead = 'null';
s.NullStringWrite = 'null';
s.JDBCDataSourceFile = '';
s.UseRegistryForSources = 'yes';
s.TempDirForRegistryOutput = 'C:\Temp';
s.DefaultRowPreFetch = '10000';
setdbprefs(s)
% Make connection to database. Note that the password has been omitted.
% Using ODBC driver.
conn = database('EnergyData','','password');
% Read data from database.
e = exec(conn,['SELECT ALL Date,Hour,DryBulb,DewPnt,SYSLoad,NGPrice,ElecPrice FROM NEData WHERE Date BETWEEN #' startDate '# AND #' endDate '# ']);
e = fetch(e);
close(e)
% Assign data to output variable.
data = e.Data;
data.NumDate = datenum(data.Date, 'yyyy-mm-dd') + (data.Hour-1)/24;
% Close database connection.
close(conn)