- Pass the input to the 'MATLAB Function' block. For more information on this block, refer to this documentation: https://www.mathworks.com/help/simulink/slref/matlabfunction.html .
- Inside the block, check for any invalid input. Use the 'error' function to stop the simulation. For more details on this function, refer to the documentation: https://www.mathworks.com/help/matlab/ref/error.html .
Is there a way to stop simulation, when an error case is met.
조회 수: 5 (최근 30일)
이전 댓글 표시
In simulink, if an error occurs (eg: invalid input parameters), is there a way to stop simulation at that point.
I know below options
1) Stop block - This will stop only after the current time step. I want to stop right there.
2) Assertion block - This block will do. But it is not recomended for code generation.
3) If else - This will also do.. But I am searching for any other logic for sudden stopping.
Please support.
댓글 수: 0
답변 (1개)
Tejas
2024년 11월 26일 5:26
To abruptly stop a simulation, one approach is to use a 'MATLAB Function' block that checks whether the input is valid. If the input is found to be invalid, it triggers an error and halts the simulation.
Here is a simple example of this approach. In this case, any negative input is treated as invalid:
function y = fcn(u)
if u <0
error("Invalid Input");
end
y = u;
end
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!