%% Load my model 
dataModel    = loadModel('OneStep');

%% Simulatate our "real model"
% we use the nominal model to generate some data
exp1 = constructExperiment(30*60, 10);
data = simulate(dataModel, exp1);


%% Scramble the parameters onthe model
m   = dataModel;
m.p = m.p.*random('log',0,0.5,size(dataModel.p));
m   = postProcessModel(m);

beforeFit = simulate(m, exp1);

plot(data.t, data.y(data.t), 'o'); hold on;
plot(beforeFit.t, beforeFit.y(beforeFit.t), '--'); hold off;


%% Fit the new model to data generated from the old model
obj = constructObjectiveOutputISE(m, 1:m.nY, data.y);
[mFit,G] = fitParameters(m, obj, exp1);


%% Plot the results
afterFit = simulate(mFit, exp1);
plot(data.t, data.y(data.t), 'o'); hold on;
plot(beforeFit.t, beforeFit.y(beforeFit.t), '--');
plot(afterFit.t, afterFit.y(afterFit.t), '-');
hold off;