MATLAB Interactive Programming Example: GUI interface programming 1

Source: Internet
Author: User
Tags reserved

MATLAB is the commercial mathematics software produced by American MathWorks Company, which is used in the advanced Technical Computing language and interactive environment for algorithm development, data visualization, data analysis and numerical calculation, mainly including MATLAB and Simulink.

A graphical user interface (GUI) is a way of interacting between a user and a computer program, and is a way for users to communicate information with a computer. Tools/Materials

MATLAB Guide Toolbox Method/Step 1

The procedure we are going to take is an example of a color image processing experiment, using this program to practice our GUI foreground design.

Program function Description: With color image processing and preservation and music playback function as shown in Figure 2

In the command window of MATLAB, enter the Guide command, open the Guidequick start window, select the Create new GUI point OK to generate a fresh fig file as shown below: 3

Right-click the window, open the property settings to modify the Figur window name, click on the name item can change us to xiaobotest.fig, and then we drag in the window, and a few buttons for interactive program event trigger, made to the foreground as shown in Figure 4

The front desk section next we will make the Window menu, click Tools Select Menu Editor

Next to the action appears a window point new menu, select this item and then click New menu to add a catalog item, select Untiled1 can see its properties can be modified by the label is used to display the text description with the tag equivalent to the handle for the operation of the following we open the table The tag value for the item is open as shown below

After the above steps to complete the menu, the function on the open file to save music playback stop, such as the following image

Following the event action of each menu item, click View to open the callback function

function Openfile_callback (hobject, EventData, handles) This is what the open operation corresponds to. We add the following code

Each of the following actions as above add code to save RGB operation picture and HSI operation picture

function Savergb_callback (hobject, eventdata, handles)

function Savehsi_callback (hobject, eventdata, handles)

For the button operation, such as the RGB histogram operation we put on the RGB histogram point right-click the following figure code as follows

function Pushbuttonrgb_callback (hobject, eventdata, handles)

Technical Detail Description:

Where the implementation of the menu optional is not selectable is

Set (Handles.savefile, ' Enable ', ' off ');

Set (Handles.savergb, ' Enable ', ' off ');

Set (HANDLES.SAVEHSI, ' Enable ', ' off ');

Set (Handles.saveph, ' Enable ', ' off ');

Set (Handles.savejr, ' Enable ', ' off ');

Where SaveFile is the tag value of the Save menu, for example, we manipulate the histogram to execute the following code after the display

Set (Handles.savefile, ' Enable ', ' on ');

Set (Handles.savergb, ' Enable ', ' on ');

This allows for redundant operation of the menu.

The effect of all operations is shown below:

Special Note: Add music playback function to menu options

Open the Prepared Music function menu and modify the callback function

function Start_callback (hobject, eventdata, handles)

% Hobject handle to start (see GCBO)

% eventdata reserved-to is defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

[Y,fs,bits] = Wavread (' dl.wav '); % Get Music data

AO = analogoutput (' WinSound '); % Build Hardware objects

AddChannel (ao,[1 2]); % Create sound output channel

Set (AO, ' samplerate ', Fs)% sets the sample rate

Data1 =y (:, 1); % Dual Channel

Data2 =y (:, 2);

PutData (ao,[data1 data2]); % go to sound card heap music data

% Output Music data

Setappdata (Handles.figure1, ' ao ', AO);

Start (AO);

% --------------------------------------------------------------------

function Pause_callback (hobject, eventdata, handles)

% Hobject handle to pause (see GCBO)

% eventdata reserved-to is defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

Ao=getappdata (Handles.figure1, ' ao ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.