Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab - input validation

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
like image 667
BAR Avatar asked Dec 17 '22 17:12

BAR


2 Answers

I use assert:

assert(Length>0,'Length is less than zero, exiting.')

see here

like image 86
rymurr Avatar answered Dec 27 '22 08:12

rymurr


You can use Matlabs built in function assert (type doc assert or help assert)

 assert(Length > 0, 'your error msg')
like image 21
Chris R Avatar answered Dec 27 '22 08:12

Chris R