Why am i getting the error 'Undefined function or variable 'Av_Daily_Temp'' on the command window when i try to run the function, loadForecast(date, Av_Daily_Temp, isHoliday) ? Below is the the code
Show older comments
function y = loadForecast(date,Av_Daily_Temp,isHoliday)
% LOADFORECAST performs a day-ahead load forecast using a pre-trained
% Neural-Network model
% USAGE:
%y = loadForecast(model, date, hour, Av_Daily_Temp, isWorkingDay);
% Process Inputs
% Process inputs
date = datenum(date,'yyyy-mm-dd');
%%
if date < 7e5 % Convert from Excel numeric date to MATLAB numeric date if necessary
date = x2mdate(date);
end
%% Classification of Dates
% Check if date is a holiday
if iscell(isHoliday)
isHoliday = isHoliday{1};
end
if ischar(isHoliday)
if strcmpi(isHoliday(1),'N')
isWorkingDay = true;
else
isWorkingDay = false;
end
else
isWorkingDay = ~isHoliday;
end
isWorkingDay = logical(isWorkingDay) & ~ismember(weekday(date),[1 7]);
%% Import data
% Import historical loads from the database
try
data = fetchDBLoadData(date-7, date-1);
catch ME %#ok<NASGU>
%% Import historical loads from MAT file
s = load('C:\ZETDC Electricity Load Forecasting\Load\Data\DBLoadData.mat');
data = s.data;
ind = data.NumDate >= date-7 & floor(data.NumDate) <= date-1;
data.Hour = data.Hour(ind);
data.Av_Daily_Temp = data.Av_Daily_Temp(ind);
data.SYSLoad = data.SYSLoad(ind);
data.NumDate = data.NumDate(ind);
end
if isempty(data.SYSLoad)
error('Not enough historical data for forecast.');
end
ave24 = filter(ones(24,1)/24, 1, data.SYSLoad);
loadPredictors = [data.SYSLoad(1:24) data.SYSLoad(end-23:end) ave24(end-23:end)];
%% Create predictor matrix
% Av_Daily_Temp, Hour, Day, isWkDay, PrevWeek, PrevDay, Prev24
X = [Av_Daily_Temp (1:24)' weekday(date)*ones(24,1) isWorkingDay*ones(24,1) loadPredictors];
%% Load Models
% Load models
try
% Load from a location where updated models can be stored
model1 = load('C:\ZETDC Electricity Load Forecasting\Load\Models\NNModel.mat');
% model2 = load('C:\ZETDC Electricity Load Forecasting\Load\Models\TreeModel.mat');
catch %#ok<CTCH>
model1 = load('C:\ZETDC Electricity Load Forecasting\Load\Models\NNModel.mat');
% model2 = load('Models\TreeModel.mat');
end
%% Perform Predicton
% Perform prediction
try
y1 = sim(model1.net, X')';
catch ME
% For debugging purposes if necessary
save 'error.mat' ME model1 %model2
y1 = zeros(24,1);
end
y2 = predict(model, X);
% Create load profile plot
fig = clf;
if isdeployed
set(fig,'Visible','off')
end
plot([y1 y2]/1e3, '.-');
xlabel('Hour');
ylabel('Load (x1000 MW)');
title(sprintf('Load Forecast Profile for %s', datestr(date)))
grid on;
legend('NeuralNet','BaggedTree','Location','best');
print -dmeta
y = [y1 y2];
%#function TreeBagger
%#function CompactTreeBagger
%#function network
%#function network\sim
%#function mae
Answers (1)
madhan ravi
on 4 Dec 2018
0 votes
Because you didn't define the input arguments while calling the function.
P.S- I won't look through your hundred lines of codes.
2 Comments
TINEI MUNHENZVA
on 4 Dec 2018
madhan ravi
on 4 Dec 2018
I have no idea how to interpret your code and don't accept the answer if you didn't get the answer to your question
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!