⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zhang3.m

📁 控制系统仿真中的频率特性的MATLAB源码
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = zhang3(varargin)
% ZHANG3 M-file for zhang3.fig
%      ZHANG3, by itself, creates a new ZHANG3 or raises the existing
%      singleton*.
%
%      H = ZHANG3 returns the handle to a new ZHANG3 or the handle to
%      the existing singleton*.
%
%      ZHANG3('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ZHANG3.M with the given input arguments.
%
%      ZHANG3('Property','Value',...) creates a new ZHANG3 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before zhang3_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to zhang3_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 zhang3

% Last Modified by GUIDE v2.5 12-Jun-2005 18:39:06
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @zhang3_OpeningFcn, ...
                   'gui_OutputFcn',  @zhang3_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 zhang3 is made visible.
function zhang3_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 zhang3 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = zhang3_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 edit1_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit1 (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 edit1_Callback(hObject, eventdata, handles)% hObject    handle to edit1 (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 edit1 as text%        str2double(get(hObject,'String')) returns contents of edit1 as a double% --- Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit2 (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 edit2_Callback(hObject, eventdata, handles)% hObject    handle to edit2 (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 edit2 as text%        str2double(get(hObject,'String')) returns contents of edit2 as a double% --- 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 on button press in radiobutton1.function radiobutton1_Callback(hObject, eventdata, handles)% hObject    handle to radiobutton1 (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 radiobutton1
%选择单选按钮set(handles.radiobutton1,'value',1)
set(handles.radiobutton2,'value',0)
set(handles.radiobutton3,'value',0)
set(handles.radiobutton4,'value',0)
%获得输入值
   z=str2num(get(handles.edit1,'string'))
    p=str2num(get(handles.edit2,'string'))
    k=str2num(get(handles.edit3,'string'))
    sys1=zpk(z,p,k)
    %将零极点模型转换为传递函数模型
[A,B,C,D]=zp2ss(z,p,k)
[num,den]=ss2tf(A,B,C,D)
%绘制开环bode图并标注
    w=logspace(-1,2)
    [m1,p1]=bode(num,den,w)
    subplot('position',[0.44,0.65,0.48,0.2])
    amp=20*log10(m1)
    semilogx(w,amp)
title('开环bode图')
    ylabel('幅值') 
    grid on
    subplot('position',[0.44,0.4,0.48,0.18])
    semilogx(w,p1)
    xlabel('频率')
    ylabel('相角')
    grid on
    %计算稳定裕量[Gm,Pm,Wcg,Wcp]=margin(sys1)
    set(handles.edit4,'string',Gm)
  set(handles.edit5,'string',Pm)
  set(handles.edit6,'string',Wcg)
  set(handles.edit7,'string',Wcp)
    set(handles.text5,'visible','on')
    set(handles.text6,'visible','on')
    set(handles.text7,'visible','on')
    set(handles.text8,'visible','on')
    set(handles.edit7,'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 radiobutton2.function radiobutton2_Callback(hObject, eventdata, handles)% hObject    handle to radiobutton2 (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 radiobutton2
%选择单选按钮set(handles.radiobutton2,'value',1)
set(handles.radiobutton1,'value',0)
set(handles.radiobutton3,'value',0)
set(handles.radiobutton4,'value',0)
%获得输入值  z=str2num(get(handles.edit1,'string'))
    p=str2num(get(handles.edit2,'string'))
     k=str2num(get(handles.edit3,'string'))
    sys=zpk(z,p,k)
    %将零极点模型转换为传递函数模型
 [A,B,C,D]=zp2ss(z,p,k)
[numo,deno]=ss2tf(A,B,C,D)
%由开环传递函数得到闭环传递函数
numc=numo
n=poly2sym(numo)
d=poly2sym(deno)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -