这是官网例子(
最近在尝试给simulink与appdesigner进行打包成exe,但发现用stateflow回调数据,以及监听器回调数据都无法把simulink文件一起放进去,在官网看到这个,找不到y到底是哪里来的。
try
app.toggleUIC('off', 'Simulating ...');
% create the simulation input
simInp = Simulink.SimulationInput('MassSpringDamperModel');%给信号输入仿真文件加一个句柄。
% set the parameters for this run
simInp = simInp.setVariable('k',app.StiffnessSpinner.Value);
simInp = simInp.setVariable('m',app.MassSpinner.Value);
simInp = simInp.setVariable('b',app.DampingSpinner.Value);
simInp = simInp.setVariable('x0',app.InitialPositionEditField.Value);%输入变量,也就是改变其中的变量。
% set the model parameters for this run设置运行时间给这个文件。
stopTimeStr = num2str(app.StopTimeSpinner.Value);
simInp = simInp.setModelParameter('StopTime', stopTimeStr);
% set the external input for this run,
simInp.ExternalInput = app.externalInput();
% configure simInp for deployment,
simInp = simulink.compiler.configureForDeployment(simInp);
% DEBUG TIP: Comment out the line above for faster debug
% iterations when runnng this app in the MATLAB desktop.
% run
simOut = sim(simInp);
% extract and plot the results,
** t = simOut.y.time;
yp = simOut.y.signals(1).values;
yv = simOut.y.signals(2).values;**
plot(app.PositionUIAxes, t, yp);
plot(app.VelocityUIAxes, t, yv);
catch ME
errordlg(ME.message);
end
app.toggleUIC('on', 'Simulate');