flystar 发表于 2009-1-16 01:08

MATLAB-GUI编程案例

function varargout = test_gui_1(varargin)
% TEST_GUI_1 M-file for test_gui_1.fig
%      TEST_GUI_1, by itself, creates a new TEST_GUI_1 or raises the existing
%      singleton*.
%
%      H = TEST_GUI_1 returns the handle to a new TEST_GUI_1 or the handle to
%      the existing singleton*.
%
%      TEST_GUI_1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TEST_GUI_1.M with the given input arguments.
%
%      TEST_GUI_1('Property','Value',...) creates a new TEST_GUI_1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before test_gui_1_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to test_gui_1_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help test_gui_1

% Last Modified by GUIDE v2.5 09-Jan-2009 11:21:14

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @test_gui_1_OpeningFcn, ...
                   'gui_OutputFcn',  @test_gui_1_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before test_gui_1 is made visible.
function test_gui_1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to test_gui_1 (see VARARGIN)

% Choose default command line output for test_gui_1
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

%fly
handles.data=0;
guidata(hObject, handles);
%fly

% UIWAIT makes test_gui_1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = test_gui_1_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on selection change in popupmenu_zeta.
function popupmenu_zeta_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu_zeta (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%fly
val=get(hObject,'value');
switch val
    case 1
        handles.data=0;
    case 2
        handles.data=0.3;
    case 3
        handles.data=0.5;
    case 4
        handles.data=0.707;
end
guidata(hObject,handles);
%fly

% Hints: contents = get(hObject,'String') returns popupmenu_zeta contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu_zeta


% --- Executes during object creation, after setting all properties.
function popupmenu_zeta_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu_zeta (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton_red.
function pushbutton_red_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_red (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%fly
x=0:0.1:20;
zeta=handles.data;
y=1-1/sqrt(1-zeta^2)*exp(-zeta*x).*sin(sqrt(1-zeta^2)*x+acos(zeta));
plot(x,y,'r');
axis();
%fly

% --- Executes on button press in pushbutton_blue.
function pushbutton_blue_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_blue (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%fly
x=0:0.1:20;
zeta=handles.data;
y=1-1/sqrt(1-zeta^2)*exp(-zeta*x).*sin(sqrt(1-zeta^2)*x+acos(zeta));
plot(x,y,'b');
axis();
%fly


% --- Executes on button press in pushbutton_fly.
function pushbutton_fly_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_fly (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%fly
%plot(3,0.7,'r*');
pushbutton_clear_Callback(hObject, eventdata, handles);
a=0.1;
for i=1:5
    a=a+0.3;
    text(2,a,'fly is the best','color','red','fontsize',24,'fontname','courier');
end
axis();
%fly


% --- Executes on button press in pushbutton_clear.
function pushbutton_clear_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_clear (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%fly
plot(10,1,'w');
axis();
%fly


% --- Executes on button press in pushbutton_move.
function pushbutton_move_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_move (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%fly
x=0:0.1:20;
zeta=handles.data;
for i=1:12
    y=1-1/sqrt(1-zeta^2)*exp(-zeta*x).*sin(sqrt(1-zeta^2)*x+acos(zeta));
    if i-3*fix(i/3)==1
        plot(x+i-2*fix(i/2),y,'b');pause(0.05);axis();
    elseif i-3*fix(i/3)==2
        plot(x+i-2*fix(i/2),y,'r');pause(0.05);axis();
    else
        pushbutton_fly_Callback(hObject, eventdata, handles);pause(0.05);
    end
end
%fly

raosu 发表于 2009-1-16 22:05

看看!!!

chenggaoynws 发表于 2009-7-16 22:00

是干什么的gui啊

gtyoyo 发表于 2010-4-16 23:11

看看..................还不错!!!!!!!!!!!!!!!

tangshanzhi 发表于 2010-4-18 18:30

………………学习学习。………………

gssrb 发表于 2010-4-29 00:20

额滴个天哪!:funk:funk:funk:funk:funk:

发表于 1970-1-1 08:00

wajm_011 发表于 2010-8-12 08:21

看看..................还不错!!!!!!!!!!!!!!!

三斤 发表于 2011-1-24 13:59

??????????这是什么东东?

杨帆 发表于 2011-1-29 12:53

看看!!!
页: [1] 2
查看完整版本: MATLAB-GUI编程案例