《matlab》GUIDE develops graphical user interface

1.Experimental tasks and purposes

1. Understand the basic controls of GUI.

2. Master the method of creating GUI through GUIDE.

3. Master the method of creating GUI through program.

2.Experimental content

1. Use GUIDE to create a graphical interface, including a command button and a label. The label is initially displayed as 0, and the label number increases by 1 each time the button is clicked.

2. Use the program to create the following graphical interface. You can switch the color of the image through the drop-down list box.

3. Experimental process andresults

1. Use GUIDE to create a graphical interface, including a command button and a label. The label is initially displayed as 0, and the label number increases by 1 each time the button is clicked.

(Part of the main implementation code)

function pushbutton1_Callback(hObject, eventdata, handles)

persistent count;

if isempty(count)

    count=0;

end;

count=count+1;

handles.str1=int2str(count);

set(handles.text2,'string',handles.str1);

2. Use the program to create the following graphical interface. You can switch the color of the image through the drop-down list box.

function [] = example()

S.fh = figure('units','normalized','position',[0.1 0.1 0.3 0.3],...

           'menubar','none','name','example','numbertitle','off',...

            'resize','off');

S.text = uicontrol('style','text','unit','normalized','position',[0.1 0.85 0.4 0.05],...

                    'string','change color');

S.pop = uicontrol('style','popupmenu','unit','normalized','position',[0.6 0.8 0.3 0.1],...

                    'string',{ 'red';'green';'blue';'yellow';'black';'cyan';'magenta'});

S.axes = axes('unit','normalized','position',[0.1 0.1 0.8 0.7]);

 x = 0:pi/50:8*pi;

y = sin(x);

axes(S.axes);

S.hplot = plot(x,y,'color',[1 0 0]);

set(S.pop,'callback',{@mycallback,S});

function mycallback(obj,event,S)

val = get(obj,'Value');

switch val

    case 1

        set(S.hplot,'color',[1 0 0]);

    case 2

        set(S.hplot,'color',[0 1 0]);

    case 3

        set(S.hplot,'color',[0 0 1]);        

    case 4

        set(S.hplot,'color',[1 1 0]);

    case 5

        set(S.hplot,'color',[0 0 0]);        

    case 6

        set(S.hplot,'color',[0 1 1]);

    case 7

        set(S.hplot,'color',[1 0 1]);

end

 

 

 

おすすめ

転載: blog.csdn.net/jian091309/article/details/131797704