Why do I receive an "Undefined function or variable" for "simout" inside an Assertion block callback in Simulink 8.5 (R2015a)?
조회 수: 3 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2009년 6월 27일
편집: MathWorks Support Team
2016년 10월 26일
When we use following commands inside the callback of Assertion block and simulate the model, an error is generated which mentions that the variable SIMOUT cannot be found.
set_param(bdroot,'SimulationCommand','pause');
disp('Simulation paused.');
evalin('base','plot(simout.signals.values)');
disp('Data plotted.');
set_param(bdroot,'SimulationCommand','continue')
However using the following command from MATLAB Command Prompt works fine:
plot(simout.signals.values)
채택된 답변
MathWorks Support Team
2016년 10월 26일
The error message is due to the following missing callback
set_param(bdroot,'SimulationCommand','WriteDataLogs')
Here is what happens without the missing callback to WriteDataLogs:
- The assertion block runs with non-zero input, and executes the callback
- The command "set_param(bdroot,'SimulationCommand','pause')" sets the parameter.
- The command "disp('Simulation paused.')" prints to the command window.
- The command "evalin('base','plot(simout.signals.values)')" fails because simout is not yet in the base workspace.
- The solver sees that parameter SimulationCommand' is 'pause', so it does not start another time step.
Adding the missing callback makes the 'To workspace' block write its data to the workspace immediately, so it is available when the plot command executes.
There is one additional issue with the code supplied in the question: you cannot pause and resume simulation within an Assertion block callback. As mentioned in the documentation, setting "SimulationCommand" to "pause" or "continue" makes a request to the solver - it does not cause immediate action. In this case, the solver will not process that request until after the callback finishes. Thus, throughout the execution of the callback, the "SimulationStatus" is "running." The call to "set_param" that is supposed to set "SimulationCommand" to "continue" will be ignored, and when the callback exits the simulation will pause. Because the execution of the callback happens within one solver step, pausing and resuming is unnecessary here. The correct callback code would be:
set_param(bdroot,'SimulationCommand','WriteDataLogs')
evalin('base','plot(simout.signals.values)');
disp('Data plotted.');
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!