Doug's MATLAB Video Tutorials

February 5th, 2008

MATLAB Basics: Change the string on a button when pushed

January t-shirt winner will be announced on Friday. There is no survey for this video, but you can still get in on last week’s survey to win a MATLAB t-shirt. This two and a quarter minute video shows how to change the string on a button when pushed. Similar techniques can be used for lots of different GUI actions.
iconFiles.jpglazy.jpg

2 Responses to “MATLAB Basics: Change the string on a button when pushed”

  1. Keith replied on :

    Hi Doug,

    I’ve been looking through your excellent GUIDE tutorials and trying to find the answer to what I feel like is probably a really dumb question. I have a function in my gui that does all the real work/number crunching of my program. What I would like to do is to have an indicator that tells the user that the program is actually executing and alerts him when the new results have been computed. Right now I’m trying to do this with just a non-editable text box. When my RunSimulation() function starts, the first thing I do is:

    set(handles.StatusBar, 'String', 'Calculating...');
    guidata(handles.StatusBar, handles);
    

    and the last thing I do in the function (after all the computation is complete) is:

    set(handles.StatusBar, 'String', 'Ready.');
    guidata(handles.StatusBar, handles);
    

    What happens though is that the StatusBar only ever says “Ready.” In the matlab window, though, it prints out stuff that confirms that something is actually going on inside the program.

    I guess my question is: when do the contents of the various UI elements actually get updated and/or how can I force particular elements to change immediately when I set new contents?

    Thanks,
    Keith

  2. Keith replied on :

    Sorry, just discovered

    drawnow

    . All works now.

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


MathWorks

Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

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