文章目录
- 效果
- 代码
效果
plot 是画图
hold是hold on
show是显示
clear是清除坐标轴
代码
function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_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 untitled
% Last Modified by GUIDE v2.5 09-Oct-2023 20:03:32
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_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 untitled is made visible.
function untitled_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 untitled (see VARARGIN)
% Choose default command line output for untitled
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
func_init_para(handles);
% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled_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 listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
global Para;
func_get_listbox(handles);
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles) %plot
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
func_plot(handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles) %hold
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Para;
Para.hold_tile = get(handles.pushbutton2,'String');
if strcmp(Para.hold_tile,'hold')
set(handles.pushbutton2,'String','unhold');
else
set(handles.pushbutton2,'String','hold');
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles) %clear
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Para;
cla(Para.axes);
legend(Para.axes,'off')
title(Para.axes,{})
xlabel(Para.axes,{})
ylabel(Para.axes,{})
Para.DisplayName = {};
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles) %show
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Para;
func_get_listbox(handles);
tmpinfo = Para.lbox2_info;
tmpinfo = char(tmpinfo{:});
pha = Para.(tmpinfo);
fra = Para.x;
set(handles.uitable1,'Data', [fra',pha']); % 鍦ㄨ〃鏍间腑鏄剧ず
set(handles.uitable1,'ColumnName' , {'x',tmpinfo});
function func_get_listbox(handles)
global Para;
str_1 = get(handles.listbox1,'String');
val_1 = get(handles.listbox1,'Value');
Para.lbox2_info = str_1(val_1);
function func_plot(handles)
global Para;
func_get_listbox(handles);
tmpinfo = Para.lbox2_info;
tmpinfo = char(tmpinfo{:});
pha = Para.(tmpinfo);
fra = Para.x;
Para.hold_tile = get(handles.pushbutton2,'String');
if strcmp(Para.hold_tile,'hold')
hold(Para.axes,'on');
else
hold(Para.axes,'off');
end
Para.fig = plot(Para.axes,fra,pha);
grid(Para.axes,'on');
xlabel(Para.axes,'x')
ylabel(Para.axes,tmpinfo)
Para.DisplayInfo = strcat(tmpinfo);
func_add_DisplayName;
function func_add_DisplayName
global Para;
DisplayInfo = Para.DisplayInfo;
if isempty(Para.DisplayName)
Para.DisplayName{1} = DisplayInfo;
else
Para.DisplayName{size(Para.DisplayName,2)+1} = DisplayInfo;
end
legend(Para.axes,Para.DisplayName);
function func_init_para(handles)
global Para;
Para.DisplayName = [];
Para.axes = handles.axes1;
handles.axes1.Toolbar.Visible = 'on';
Para.x = -pi+0.01:0.01:pi-0.01;
Para.sin = sin(Para.x);
Para.cos = cos(Para.x);
Para.tan = tan(Para.x);
Para.cot = cot(Para.x);