Archive for November, 2007

Advanced, GUI, MATLAB

Matlab GUI Tutorial - Integrating Simulink Model into a GUI

Introduction

Matlab Logo This tutorial will show you how to easily interface a Simulink Model with GUIDE using two different methods. In this tutorial, you will learn how to pass parameters to a Simulink model without using the set_param command and without having the Simulink Model open (which is how the Matlab Help does it).

Since Simulink can be used to easily model a variety of systems using an intuitive block diagram format, it would be advantageous to use it in conjunction with GUIs. Interfacing the Simulink Model with GUIDE will makes it easier for end-users to change key parameters and to view simulations without having to deal directly with Simulink.

Continue Reading »

Pages: 1 2 3 4

Basic, GUI, MATLAB

Matlab GUI Tutorial - Custom Background Images and Custom Buttons

Introduction

Matlab Logo Changing the way your GUI is presented can make your GUI more appealing to the eye. This tutorial will show you how to add a background image to your GUI. In addition, it will also show you how to modify your buttons to display custom images too.

GUI with Background Image

Continue Reading »

Pages: 1 2 3

Advanced, GUI, MATLAB

Matlab GUI Tutorial - Basic Data Processing Tool

Introduction

Matlab Logo This tutorial outlines the basic skeleton for a data processing GUI. The tutorial provides you with the visual aspect of the GUI via download, and then goes on to provide the code to each component callback. This tutorial draws upon many of the basic GUI elements: adding files to a listbox, parsing data, plotting data onto the GUI, saving GUI plots, disabling/enabling buttons, exporting data to Excel format, and many other things.

If you just want to see the finished product, you can download the source files here. The source files include the GUI files, the m-files for the sub functions, and 3 sample data files. You can play around with this GUI to learn more about how GUIs are designed and coded. You can also use this GUI as a foundation for developing more advanced GUIs. I highly encourage that you take the time to look through the source code, and to hack it to your content. Feel free to modify it so that it suits your purposes.

Data Processing GUI

Continue Reading »

Pages: 1 2 3 4 5 6 7

Basic, GUI, MATLAB

Matlab GUI Tutorial - Close GUI Confirmation

Introduction

Matlab Logo This tutorial will show you how to create a confirmation window when you attempt to close the GUI. Sometimes, the user might accidentally close the GUI window without meaning to. To protect against this, we can implement a confirmation window that appears when the user attempts to close the GUI. This feature can protect the user from losing any work that has been performed.

close confirmation window

Continue Reading »

Pages: 1 2

Advanced, GUI, MATLAB

Matlab GUI Tutorial - Disable Mouse Clicking

Introduction

Matlab Logo This tutorial will show you how to implement a "busy" status wherein the user is informed that the Matlab GUI is processing a task, and cannot accept more tasks until the current task is complete. This will be accomplished by disabling all of the buttons on the GUI and changing the mouse pointer to an hourglass icon. This feature is useful when you have a function callback that takes a couple of seconds to run. During this time, you want to prevent the user from pressing other buttons that may break your GUI or interrupt your function.

This tutorial is written for those with some experience creating a Matlab GUI. If you’re new to creating GUIs in Matlab, you should visit this tutorial first. Basic knowledge of Matlab and an understanding on how data is shared among callbacks is highly recommended. Matlab version 2007a is used in writing this tutorial. Both earlier versions and new versions should be compatible as well (as long as it isan’t too outdated). Let’s get started!

Disabling and Enabling Buttons, Changing the Mouse Cursor

  1. First, download the sample GUI here. Unzip the files and place them wherever you please.

  2. Now, type guide at the command prompt.

    Command prompt

  3. Choose to open the sample GUI by clicking on "Open Existing GUI". Click on "Browse" to locate where you saved the GUI files.

    GUIDE Screen

  4. Here is what the GUI should look like when you open it:

    GUI Figure

  5. Click on the mfile icon icon on the GUI figure to bring up the accompanying .m file.

  6. Now, add the following code to the end of the .m file. I wrote here that I was strongly against writing functions in this manner, but I think this is a reasonable exception.

    function disableButtons(handles)
    %change the mouse cursor to an hourglass
    set(handles.figure1,'Pointer','watch');
     
    %disable all the buttons so they cannot be pressed
    set(handles.pushbutton1,'Enable','off');
    set(handles.pushbutton2,'Enable','off');
    set(handles.pushbutton3,'Enable','off');
     
    function enableButtons(handles)
    %change the mouse cursor to an arrow
    set(handles.figure1,'Pointer','arrow');
     
    %enable all the buttons so they can be pressed
    set(handles.pushbutton1,'Enable','on');
    set(handles.pushbutton2,'Enable','on');
    set(handles.pushbutton3,'Enable','on');
  7. Now, add the following code to each of the button callback functions.

    disableButtons(handles);
    refresh(busyStatus) %redraws the GUI to reflect changes
    keyboard
    enableButtons(handles);
  8. Now, save your .m file and run the GUI. You should see the following GUI appear

    GUI

  9. Press any of the buttons. You should see the following change reflected on your GUI now. Notice that the mouse cursor has also changed to an hourglass icon.

    GUI Buttons Disabled

  10. Now, type return at the command prompt to finish the callback. You should notice that the GUI has returned back to normal.

  11. If you plan on using this code in your own GUI, you won't be needing the "keyboard" command. Instead, your code would look this:

    disableButtons(handles);
    refresh(busyStatus) %redraws the GUI to reflect changes
     
    %insert your code here, "keyboard" is not needed
    %it was merely used as a demonstration example
     
    %during this part of your code, the buttons are disabled
    %when your code is done running, we enable the buttons again
     
    enableButtons(handles);

This is the end of the tutorial.

Next »