初级会员
注册日期: 2008-07-01
年龄: 41
帖子: 5
声望力: 0
|
这个程序完整的代码是这样的:
function varargout = ex71(varargin)
% EX71 M-file for ex71.fig
% EX71, by itself, creates a new EX71 or raises the existing
% singleton*.
%
% H = EX71 returns the handle to a new EX71 or the handle to
% the existing singleton*.
%
% EX71('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EX71.M with the given input arguments.
%
% EX71('Property','Value',...) creates a new EX71 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ex71_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ex71_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 ex71
% Last Modified by GUIDE v2.5 30-Jun-2008 21:38:38
% Begin initialization code - DO NOT EDITgui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ex71_OpeningFcn, ...
'gui_OutputFcn', @ex71_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before ex71 is made visible.function ex71_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 ex71 (see VARARGIN)
% Choose default command line output for ex71
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ex71 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = ex71_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 button press in ex71_plot.
function ex71_plot_Callback(hObject, eventdata, handles)
% hObject handle to ex71_plot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
flag=get(handles.ex71_fun,'Value'); %get the value of the popupmenue
w=get(handles.ex71_input,'Value'); %get the value of the slider
t=0:0.001:2*pi; %define the array t
switch flag
case 1
y=sin(w*t); %through the value of the popupmenue
case 2 %to caculate the sin, cos, tan,cot
y=cos(w*t);
case 3
y=tan(w*t);
case 4
y=cot(w*t);
end
axes(handles.ex71_axes) %claim the graph drawed on the ex71_axes
plot(t,y)
% --- Executes on button press in ex71_close.
function ex71_close_Callback(hObject, eventdata, handles)
% hObject handle to ex71_close (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close
% --- Executes on slider movement.
function ex71_input_Callback(hObject, eventdata, handles)
% hObject handle to ex71_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function ex71_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to ex71_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in ex71_gridon.
function ex71_gridon_Callback(hObject, eventdata, handles)
% hObject handle to ex71_gridon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ex71_gridon
flag=get(hObject,'Value'); %get the value of this control
if flag==1; %if the value is 1 then use the grid
grid on;
else
grid off; %else take away the grid
end
% --- Executes on selection change in ex71_fun.
function ex71_fun_Callback(hObject, eventdata, handles)
% hObject handle to ex71_fun (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns ex71_fun contents as cell array
% contents{get(hObject,'Value')} returns selected item from ex71_fun
flag=get(hObject,'Value'); %get the value of this control
w=get(handles.ex71_input,'Value'); %get the value of the slider
if w==1
string='x)';
else
string=[num2str(w),'x]'];
end
switch flag %dymatic display the graphic
case 1
set(handles.ex71_text,'String',['The function is y=sin(',string]);
case 2
set(handles.ex71_text,'String',['The function is y=cos(',string]);
case 3
set(handles.ex71_text,'String',['The function is y=tan(',string]);
case 4
set(handles.ex71_text,'String',['The function is y=cot(',string]);
end
% --- Executes during object creation, after setting all properties.
function ex71_fun_CreateFcn(hObject, eventdata, handles)
% hObject handle to ex71_fun (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
|