MATLAB/Simulink code update
This commit is contained in:
parent
d2179071db
commit
d6b69acb17
28 changed files with 956 additions and 266 deletions
|
@ -29,17 +29,20 @@ classdef weather_predictor < matlab.System
|
|||
num = 2;
|
||||
end
|
||||
function num = getNumOutputsImpl(~)
|
||||
num = 1;
|
||||
num = 2;
|
||||
end
|
||||
function dt1 = getOutputDataTypeImpl(~)
|
||||
function [dt1, dt2] = getOutputDataTypeImpl(~)
|
||||
dt1 = 'double';
|
||||
dt2 = 'double';
|
||||
|
||||
end
|
||||
function [dt1, dt2] = getInputDataTypeImpl(~)
|
||||
dt1 = 'double';
|
||||
dt2 = 'double';
|
||||
end
|
||||
function sz1 = getOutputSizeImpl(obj)
|
||||
sz1 = [obj.N 2];
|
||||
function [sz1, sz2] = getOutputSizeImpl(obj)
|
||||
sz1 = [1 2];
|
||||
sz2 = [obj.N 2];
|
||||
end
|
||||
function sz1 = getInputSizeImpl(~)
|
||||
sz1 = 1;
|
||||
|
@ -47,14 +50,16 @@ classdef weather_predictor < matlab.System
|
|||
function cp1 = isInputComplexImpl(~)
|
||||
cp1 = false;
|
||||
end
|
||||
function cp1 = isOutputComplexImpl(~)
|
||||
function [cp1, cp2] = isOutputComplexImpl(~)
|
||||
cp1 = false;
|
||||
cp2 = false;
|
||||
end
|
||||
function fz1 = isInputFixedSizeImpl(~)
|
||||
fz1 = true;
|
||||
fz1 = true;
|
||||
end
|
||||
function fz1 = isOutputFixedSizeImpl(~)
|
||||
function [fz1, fz2] = isOutputFixedSizeImpl(~)
|
||||
fz1 = true;
|
||||
fz2 = true;
|
||||
end
|
||||
|
||||
|
||||
|
@ -63,13 +68,29 @@ classdef weather_predictor < matlab.System
|
|||
% Perform one-time calculations, such as computing constants
|
||||
end
|
||||
|
||||
function w = stepImpl(obj,wdb_mat,timestamp)
|
||||
function [w, w_hat] = stepImpl(obj,wdb_mat,timestamp)
|
||||
disp(timestamp)
|
||||
% Implement algorithm. Calculate y as a function of input u and
|
||||
% discrete states.
|
||||
curr_idx = find(wdb_mat(:, 1) == timestamp);
|
||||
N_idx = (1:obj.N) + curr_idx;
|
||||
w = [wdb_mat(N_idx, 18) + wdb_mat(N_idx, 19), wdb_mat(N_idx, 7)];
|
||||
|
||||
|
||||
forecast_start = timestamp + obj.TimeStep;
|
||||
forecast_end = timestamp + obj.N * obj.TimeStep;
|
||||
|
||||
xq = forecast_start:obj.TimeStep:forecast_end;
|
||||
|
||||
weather_start_idx = find(wdb_mat(:, 1) <= timestamp, 1);
|
||||
weather_end_idx = find(wdb_mat(:, 1) >= forecast_end, 1);
|
||||
weather_idx = weather_start_idx:weather_end_idx;
|
||||
|
||||
solar_direct = interp1(wdb_mat(weather_idx, 1), wdb_mat(weather_idx, 18), timestamp);
|
||||
solar_diffuse = interp1(wdb_mat(weather_idx, 1), wdb_mat(weather_idx, 19), timestamp);
|
||||
outside_temp = interp1(wdb_mat(weather_idx, 1), wdb_mat(weather_idx, 7), timestamp);
|
||||
w = [solar_direct + solar_diffuse, outside_temp];
|
||||
|
||||
solar_direct = interp1(wdb_mat(weather_idx, 1), wdb_mat(weather_idx, 18), xq)';
|
||||
solar_diffuse = interp1(wdb_mat(weather_idx, 1), wdb_mat(weather_idx, 19), xq)';
|
||||
outside_temp = interp1(wdb_mat(weather_idx, 1), wdb_mat(weather_idx, 7), xq)';
|
||||
|
||||
w_hat = [solar_direct + solar_diffuse, outside_temp];
|
||||
end
|
||||
|
||||
function resetImpl(obj)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue