How can I generate a Command Window error from Simulink block mask editor (Initialization Tab)?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Babak
el 9 de Oct. de 2012
disp() command would display whatever you want to display in the command window.
3 comentarios
Babak
el 10 de Oct. de 2012
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.
Más respuestas (2)
Kaustubha Govind
el 30 de Nov. de 2012
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 comentarios
Babak
el 30 de Nov. de 2012
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.
Ver también
Categorías
Más información sobre Simulink Environment Customization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!