Stuart’s MATLAB Videos

Watch and Learn

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the Original version of the page.

MATLAB Basics: GUI input validation 4

Posted by Doug Hull,

Two minute video shows how to validate GUI input. This makes sure that user input will not break your code. This example makes sure that the edit box value is not greater than twelve. This technique can be used for many different tests.
Other videos have been gathered here: https://blogs.mathworks.com/pick/category/video/ Other MATLAB Basics posts have been gathered here: https://blogs.mathworks.com/pick/category/matlab-basics/

4 CommentsOldest to Newest

José Ramón Menzinger replied on : 1 of 4
It is a fine Exampla but the code line: set(hObject, 'String', '12'); is IMO not realy adecuate. These kind of declarations will produce "other errors" soon or later... I find better something like: set(hObject, 'String', num2str(modeNum) ); so wenn you mustchange the treshold value you shuoldf change only one value, isn't it? Best regards! J.R.!
Doug replied on : 2 of 4
José, I totally agree with your idea here. In my video series "Cleaner Code in MATLAB" https://blogs.mathworks.com/pick/2006/12/13/cleaner-code-in-matlab-part-1-of-series/ https://blogs.mathworks.com/pick/2007/01/12/cleaner-code-in-matlab-part-two/ I talk about how you should avoid the use of Magic Numbers. Sometimes I do things for brevity in the videos that I could do better with more time. Thanks! Doug