What is a good way to validate an input or exit the program with an error message altoghether?
For example if I take an input such as
Length = input('\nEnter a length in feet: ');
How can I check if the number is greater than 0.
something like
if Length > 0 then
%%do code
else
%%Output error
%%nothing to do here so it just continues and exits
end
I use assert:
assert(Length>0,'Length is less than zero, exiting.')
see here
You can use Matlabs built in function assert
(type doc assert
or help assert
)
assert(Length > 0, 'your error msg')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With