📄 zhang4.m
字号:
function varargout = zhang4(varargin)
% ZHANG4 M-file for zhang4.fig
% ZHANG4, by itself, creates a new ZHANG4 or raises the existing
% singleton*.
%
% H = ZHANG4 returns the handle to a new ZHANG4 or the handle to
% the existing singleton*.
%
% ZHANG4('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ZHANG4.M with the given input arguments.
%
% ZHANG4('Property','Value',...) creates a new ZHANG4 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before zhang4_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to zhang4_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 zhang4
% Last Modified by GUIDE v2.5 12-Jun-2005 18:56:43
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @zhang4_OpeningFcn, ...
'gui_OutputFcn', @zhang4_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(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 zhang4 is made visible.
function zhang4_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 zhang4 (see VARARGIN)
% Choose default command line output for zhang4
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes zhang4 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = zhang4_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)
%设置当前窗口名
str='传递函数'
set(gcf,'name',str,'numbertitle','off')
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.function edit_n_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_n (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit_n_Callback(hObject, eventdata, handles)% hObject handle to edit_n (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,'String') returns contents of edit_n as text% str2double(get(hObject,'String')) returns contents of edit_n as a double% --- Executes during object creation, after setting all properties.function edit_m_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_m (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit_m_Callback(hObject, eventdata, handles)% hObject handle to edit_m (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,'String') returns contents of edit_m as text% str2double(get(hObject,'String')) returns contents of edit_m as a double% --- Executes on button press in radiobutton_bo.function radiobutton_bo_Callback(hObject, eventdata, handles)% hObject handle to radiobutton_bo (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 radiobutton_bo%选择单选按钮set(handles.radiobutton_bo,'value',1)
set(handles.radiobutton_ny,'value',0)
set(handles.radiobutton_ni,'value',0)
set(handles.radiobutton_bc,'value',0)
%获得输入值
den=str2num(get(handles.edit_m,'string'))
num=str2num(get(handles.edit_n,'string'))
sys=tf(num,den)
%绘制开环bode图并标注
w=logspace(-1,2)
[m1,p1]=bode(num,den,w)
subplot('position',[0.44,0.65,0.48,0.2])
semilogx(w,20*log10(m1))
title('开环bode图')
ylabel('幅值')
grid on
subplot('position',[0.44,0.38,0.48,0.2])
semilogx(w,p1)
xlabel('频率')
ylabel('相角')
grid on
%计算稳定裕量
[Gm,Pm,Wcg,Wcp]=margin(sys)
set(handles.edit3,'string',Gm)
set(handles.edit4,'string',Pm)
set(handles.edit5,'string',Wcg)
set(handles.edit6,'string',Wcp)
set(handles.text9,'visible','on')
set(handles.text10,'visible','on')
set(handles.text11,'visible','on')
set(handles.text12,'visible','on')
set(handles.edit3,'visible','on')
set(handles.edit4,'visible','on')
set(handles.edit5,'visible','on')
set(handles.edit6,'visible','on')
set(handles.pushbutton1,'visible','on')
set(handles.pushbutton3,'visible','off')% --- Executes on button press in radiobutton_bc.function radiobutton_bc_Callback(hObject, eventdata, handles)% hObject handle to radiobutton_bc (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 radiobutton_bc
%选择单选按钮set(handles.radiobutton_bc,'value',1)
set(handles.radiobutton_ny,'value',0)
set(handles.radiobutton_ni,'value',0)
set(handles.radiobutton_bo,'value',0)
%获得输入值
deno=str2num(get(handles.edit_m,'string'));
numo=str2num(get(handles.edit_n,'string'));
%由开环传递函数得到闭环传递函数
numcl=numo;
n=poly2sym(numo);
d=poly2sym(deno);
dencl=sym2poly(n+d);
%绘制闭环bode图并标注
w=logspace(-1,2);
[m2,p2]=bode(numcl,dencl,w);
subplot('position',[0.44,0.65,0.48,0.2]);
semilogx(w,20*log10(m2));
title('闭环bode图');
ylabel('幅值') ;
grid on;
subplot('position',[0.44,0.38,0.48,0.2]);
semilogx(w,p2);
xlabel('频率');
ylabel('相角');
grid on;
%计算稳定裕量
sys=tf(numcl,dencl)[Gm,Pm,Wcg,Wcp]=margin(sys)
set(handles.edit3,'string',Gm)
set(handles.edit4,'string',Pm)
set(handles.edit5,'string',Wcg)
set(handles.edit6,'string',Wcp)
set(handles.text9,'visible','on')
set(handles.text10,'visible','on')
set(handles.text11,'visible','on')
set(handles.text12,'visible','on')
set(handles.edit3,'visible','on')
set(handles.edit4,'visible','on')
set(handles.edit5,'visible','on')
set(handles.edit6,'visible','on')
set(handles.pushbutton1,'visible','on')
set(handles.pushbutton3,'visible','off')% --- Executes on button press in radiobutton_ny.function radiobutton_ny_Callback(hObject, eventdata, handles)% hObject handle to radiobutton_ny (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 radiobutton_ny
%选择单选按钮set(handles.radiobutton_ny,'value',1)
set(handles.radiobutton_bc,'value',0)
set(handles.radiobutton_bo,'value',0)
set(handles.radiobutton_ni,'value',0)
%获得输入值
den=str2num(get(handles.edit_m,'string'))
num=str2num(get(handles.edit_n,'string'))
sys=tf(num,den)
%绘制nyquist曲线并标注
subplot('position',[0.42,0.38,0.5,0.47])
nyquist(sys)
grid on
title('nyquist曲线')
xlabel('实轴')
ylabel('虚轴') set(handles.text9,'visible','off')
set(handles.text10,'visible','off')
set(handles.text11,'visible','off')
set(handles.text12,'visible','off')
set(handles.edit3,'visible','off')
set(handles.edit4,'visible','off')
set(handles.edit5,'visible','off')
set(handles.edit6,'visible','off')
set(handles.pushbutton3,'visible','on')
set(handles.pushbutton1,'visible','off')% --- Executes on button press in radiobutton_ni.function radiobutton_ni_Callback(hObject, eventdata, handles)% hObject handle to radiobutton_ni (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 radiobutton_ni%选择单选按钮set(handles.radiobutton_ni,'value',1)
set(handles.radiobutton_bc,'value',0)
set(handles.radiobutton_ny,'value',0)
set(handles.radiobutton_bo,'value',0)
%获得输入值
den=str2num(get(handles.edit_m,'string'))
num=str2num(get(handles.edit_n,'string'))
sys=tf(num,den)
%绘制nichols曲线并标注
subplot('position',[0.42,0.2,0.5,0.65])
nichols(sys)
grid on
ngrid
title('nichols曲线')
xlabel('开环相角 ')
ylabel('开环增益')
set(handles.text9,'visible','off')
set(handles.text10,'visible','off')
set(handles.text11,'visible','off')
set(handles.text12,'visible','off')
set(handles.edit3,'visible','off')
set(handles.edit4,'visible','off')
set(handles.edit5,'visible','off')
set(handles.edit6,'visible','off')
set(handles.pushbutton1,'visible','off')
set(handles.pushbutton3,'visible','off')% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% 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)zyx9% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% 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)close% --- Executes during object creation, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit3_Callback(hObject, eventdata, handles)% hObject handle to edit3 (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,'String') returns contents of edit3 as text% str2double(get(hObject,'String')) returns contents of edit3 as a double% --- Executes during object creation, after setting all properties.function edit4_CreateFcn(hObject, eventdata, handles)% hObject handle to edit4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit4_Callback(hObject, eventdata, handles)% hObject handle to edit4 (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,'String') returns contents of edit4 as text% str2double(get(hObject,'String')) returns contents of edit4 as a double% --- Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, eventdata, handles)% hObject handle to edit5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit5_Callback(hObject, eventdata, handles)% hObject handle to edit5 (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,'String') returns contents of edit5 as text% str2double(get(hObject,'String')) returns contents of edit5 as a double% --- Executes during object creation, after setting all properties.function edit6_CreateFcn(hObject, eventdata, handles)% hObject handle to edit6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit6_Callback(hObject, eventdata, handles)% hObject handle to edit6 (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,'String') returns contents of edit6 as text% str2double(get(hObject,'String')) returns contents of edit6 as a double% --- Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% 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)analysis2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -