File Exchange Pick of the Week

October 30th, 2007

MATLAB Basics: GUI input validation

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.


Video Content

Find the files here.

Other videos have been gathered here:
http://blogs.mathworks.com/pick/category/video/

Other MATLAB Basics posts have been gathered here:
http://blogs.mathworks.com/pick/category/matlab-basics/

4 Responses to “MATLAB Basics: GUI input validation”

  1. José Ramón Menzinger replied on :

    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.!

  2. Doug replied on :

    José,

    I totally agree with your idea here. In my video series “Cleaner Code in MATLAB”

    http://blogs.mathworks.com/pick/2006/12/13/cleaner-code-in-matlab-part-1-of-series/
    http://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

  3. Ken Rotter replied on :

    Video cutting off after 1:30 seconds today- tried three times.

  4. Doug replied on :

    Ken,

    Thank you, the file was corrupted. I have verified the fix is working now.

    Thanks,
    Doug

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • oleg: The author has implemented skewness, kurtosis and checks answering appropriately to the critic.
  • Ashok: how to store 10 or more random number in a loop a loop for i = 1:n mean(i) = input(’enter the mean value...
  • Ben: Doug, Thanks for the very helpful videos! Uitables seem like a convenient way to make a customized property...
  • oleg: Allstats has no checks, no comments and could also be improved (talking about prctile implementatio). Not to...
  • Todd: Additional information and a link to download free MATLAB and Simulink LEGO MINDSTORMS NXT code can be found at...
  • Doug: @Leo, Here is the “English version” of that code. “vec = []” makes an empty variable...
  • leo: Dear Doug I have a question in your code ‘October 9th, 2009 at 13:53′ vec = []; vec = [vec val]; I...
  • Shanker Keshavdas: You sir, are a gentleman and a scholar… No really, helped me out a lot. As to what is...
  • Quan Zheng: how can I get a copy of stepspecs.m?
  • Doug: @Lucy I think this is what you seek to move a line with the mouse in MATLAB. http://blogs.math...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.