在官网给appdesigner的一个例子中中出现simOut.y.signals(2).values,其中y是什么意思?
问题描述:
这是官网例子(
Deploying A Simulation App with Simulink Compiler
- MATLAB & Simulink
- MathWorks 中国
In this example, we use an app that is prepared in the App Designer and deploy it with Simulink Compiler.
https://ww2.mathworks.cn/help/slcompiler/ug/deploy-mass-springr-app-with-simulink-compiler.html
)
最近在尝试给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');
答
你好,这就是sim仿真出来的信号结果,具体看你的结构体解释,simOut是一个结构体变量,存在着输出信号y,然后signals(1)、signals(2)分别表示不同时刻位置和速度信号,取其值画图