How can I generate a Command Window error from Simulink block mask editor (Initialization Tab)?
조회 수: 6 (최근 30일)
이전 댓글 표시
I would like to do some input validation of the block mask parameters, and in the case that the input is out of range, output an error message.
Using "errordlg" is annoying because if the parameter is a workspace variable that changes and you've used the block in N places in the model, suddenly you have N pop-up dialogs.
Using the Command Window to display these errors is a more comfortable option. But when I try the following inside the Initialization tab of the mask editor:
if num<0
error('Number must be positive: "%s"', gcb);
end;
I get a pop-up anyway saying: Error due to multiple causes. --> Error in 'untitled/myblock': Initialization commands cannot be evaluated. --> Number must be positive: "untitled/myblock"
Is there any way to get Simulink to output to the Matlab command window?
Thanks!
댓글 수: 0
채택된 답변
Babak
2012년 10월 9일
disp() command would display whatever you want to display in the command window.
댓글 수: 3
Babak
2012년 10월 10일
I don't think or know how to do this. Please close this question with accepting the answer and create a new question with your hyperlink question such that everyone could participate answering.
추가 답변 (2개)
Kaustubha Govind
2012년 11월 30일
I think the right place to validate mask parameters is the dialog callbacks, rather than Mask Initialization. Read Dynamic Mask Dialogs for more information. This should also prevent the problem of multiple error windows popping up.
댓글 수: 2
Babak
2012년 11월 30일
error() stops execution of the code and gives a matlab error as soon as it is detected. It stops execution of matlabs mask gui fucntions which results in matlabs errors too. So for UI errors you want to spit, errordlg() should be used.
As Kaustubha mentions, if your mask user inserts variables from the mask GUI,by double clicking on the block, and you want to run some check on what the user has punched in, you should use dialog callback functions. If your mask parameters change from other places too, you may want to run a double check on them using the initialization function as well.
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!