Need some assistance with "if" command
Mostrar comentarios más antiguos
I'm trying to get my program to stop completely when given an invalid response after entering the side lengths. I've created the following:
a=input('Enter value for side a: ');
if a < 0
disp('Not a valid input.')
end
b=input('Enter value for side b: ');
if b < 0
disp('Not a valid input.')
end
c=input('Enter value for side c: ');
if c < 0
disp('Not a valid input.')
Respuesta aceptada
Más respuestas (2)
Geoff
el 28 de Jun. de 2012
Oh, the better way is to use the proper MATLAB error function:
if a < 0
error( 'Not a valid input.' );
end
Walter Roberson
el 28 de Jun. de 2012
0 votos
To get your program to stop completely you are going to need to use the command "quit", as anything else you can voluntarily do has the risk of being intercepted by a different level, such as by a try/catch block. "quit" will exit MATLAB.
Honestly, even "quit" might not be good enough, as I think "quit" would still end up running any registered onCleanup() routines rather than stopping the program completely. So possibly what you should do is write a little mex routine that deliberately dereferences an invalid pointer so that MATLAB crashes.
Categorías
Más información sobre Just for fun en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!