Doug's MATLAB Video Tutorials

July 22nd, 2008

MATLAB Basics: Adding a toolbar to a GUI

People often make their own GUIs in GUIDE and they have a data visualization. When you embed an axis in your own GUI rather than using a figure window, you lose the built in toolbar that has zoom, pan, and other goodies. You can add the widgets you want back into your GUI very easily, or even make your own custom tools for the toolbar. This short video shows you how.
iconFiles.jpgiconPod.jpg

17 Responses to “MATLAB Basics: Adding a toolbar to a GUI”

  1. Daniel Armyr replied on :

    Nicey nice. Another feature which isn’t so important you break your skull finding yourself, but allways felt that you really should find out how to do.

    –DA

  2. Sharina replied on :

    Hi Doug,

    This proves to be an excellent video.
    But can u please tell the version of MATLAB which has a toolbar edit option in it?

  3. Doug replied on :

    This video was made with 2008a.

    Doug

  4. Rachel replied on :

    Hi Doug,

    I was wondering if you could help me out?

    I have created a GUI which displays two axes. However I only want the zoom tool to be used on one of them. (I tried using zoom off, but turns the zoom tool off on both axes!) Do you know how I can achieve this?

    Thank you

    Rachel

  5. jiro replied on :

    Hi Rachel,

    Take a look at Example 3 here:

    http://www.mathworks.com/access/helpdesk/help/techdoc/ref/zoom.html

    jiro

  6. Geoff replied on :

    Sharina might like to know that toolbar editing was introduced to GUIDE in MATLAB Version 7.5 (R2007b).

  7. shakeham replied on :

    Doug, thank you very much. You posts are very useful

  8. Kaj replied on :

    Doug,

    It does not seem possible to add an ‘plot edit’ button in this way. I would like to be able to select objects plotted in the axes in my GUI. In a GUI using R14, I built a ‘plot edit’ button using the commond ‘plotedit on’, but in R2008a this does not work — it disables all my GUI buttons.

    Thanks,
    Kaj

  9. shakeham replied on :

    Hi Doug,
    Sorry this may not be the right place to ask this question. But I really find it one of the very few impossible things to do with Matlab. I’m trying to build a GUI, with a button which if clicked will open the Matlab arrayeditor and allow the user to edit some data. But as all the halting functions, like ‘pause’, ‘waitfor’ or ‘uiwait’ will take us somewhere outside the current workspace, it won’t work. There would be nothing in the arrayEditor window. I’d like some function that would hold the program right there like what we’d have with a breakpoint in debugging mode. Is it even possible? Thanks!

  10. Scott Hirsch replied on :

    Shakeham -

    You might want to try working with UITABLE instead – just wrap it in a figure. A caution – UITABLE was released in R2008A. Earlier versions (back to MATLAB 7/R14) have an undocumented version of UITABLE that works, but which is not compatible with the new version.

    - scott

  11. Abhijit Warke replied on :

    Hi Doug,

    I have plot axes in my GUI and i want to synchronize the zoom in/out function for both. Which means if i zoom in on one figure it should correspondingly zoom in on the other by same amout. Both the axes share same x-axis but there is a need to plot them on different plots and not use hold on/off to solve my situation otherwise. Is there a way to do so, thanks!

  12. dhull replied on :

    @abhijit

    look at linkaxes and linkprop.

    Doug

  13. Abhijit Warke replied on :

    Thanks dhull! ill try that..

  14. Abhijit Warke replied on :

    Hi, Another question

    hold on
    plot(handles.axes4, Data,’k');grid on
    title(handles.axes4,’\fontsize{16} Signal’)
    xlabel(handles.axes4,’\fontsize{16}Samples’)
    ylabel(handles.axes4,’\fontsize{16}\mu’)
    hold off

    grid on

    plot(handles.axes8, Data,’k');grid on
    plot(handles.axes9, Data,’k');grid on
    plot(handles.axes10,Data,’k');grid on

    this does not switch on grid on any of the axis in the GUI. How do i switch the grid on for all the axes?

    thanks in advance..

  15. dhull replied on :

    @Abhijit,

    You have to turn on the grid on an axes by axes basis.

    Doug

  16. Lindsay replied on :

    In your demo you quickly showed how to add these things to a blank figure though it appeared you executed your original main program to show the tools added actually function. I tried adding the tools without adding any callbacks and the tools did nothing.
    I didn’t see you add any code that makes the tools actually work. I thought the %default takes care of everything but apparently it doesn’t. can you elaborate why mine is not working.. am running matlab 2008b.

    thanks

  17. dhull replied on :

    @Lindsay,

    The callbacks define what happens. You must add them unless you are using pre-builts with defaults as I am.

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


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.