runSim.m 746 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
function results = runSim(model, sim_in)
% Runs a Simulink model. The `model` takes as input
% a workspace variable `sim_in` which is a matrix where
% the first column is a time stamp and the remaining
% columns are individual inputs. The model outputs to
% a workspace variable `sim_out` which is a timestamp
% object.
% The function parses the `sim_out` and returns `result`
% in the same form as `sim_in`.
stop_t = sim_in(end,1);
steps = diff(sim_in(:, 1));
minStep = min(steps(:));
set_param(model, 'StopTime', num2str(stop_t), 'MaxStep', num2str(minStep));
hazrmard's avatar
hazrmard committed
14
% set_param(model, 'StopTime', num2str(stop_t));
15
sim(model);
hazrmard's avatar
hazrmard committed
16
17
18
% results = [sim_out.Time sim_out.Data];
[y, t] = resample(sim_out.Data, sim_out.Time, 1 / minStep);
results = [t, y];
19
end