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');
你好,这就是sim仿真出来的信号结果,具体看你的结构体解释,simOut是一个结构体变量,存在着输出信号y,然后signals(1)、signals(2)分别表示不同时刻位置和速度信号,取其值画图