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

📄 lab22.m

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

% Last Modified by GUIDE v2.5 25-May-2005 13:59:11
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @lab22_OpeningFcn, ...
                   'gui_OutputFcn',  @lab22_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 lab22 is made visible.
function lab22_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 lab22 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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

%设置当前窗口名
str='0度根轨迹实验窗口';
set(gcf,'name',str,'numbertitle','off');


% --- Outputs from this function are returned to the command line.
function varargout = lab22_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 during object creation, after setting all properties.function edit_z_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit_z (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_z_Callback(hObject, eventdata, handles)% hObject    handle to edit_z (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_z as text%        str2double(get(hObject,'String')) returns contents of edit_z as a double% --- Executes during object creation, after setting all properties.function edit_p_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit_p (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_p_Callback(hObject, eventdata, handles)% hObject    handle to edit_p (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_p as text%        str2double(get(hObject,'String')) returns contents of edit_p as a double% --- Executes during object creation, after setting all properties.function edit_k_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit_k (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_k_Callback(hObject, eventdata, handles)% hObject    handle to edit_k (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_k as text%        str2double(get(hObject,'String')) returns contents of edit_k as a double% --- Executes on button press in pushbutton_sure.function pushbutton_sure_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton_sure (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)

%接受编辑框中的零极点值并绘制根轨迹图z=str2num(get(handles.edit_z,'string'))
p=str2num(get(handles.edit_p,'string'))
k=str2num(get(handles.edit_k,'string'))
sys=zpk(z,p,k)
subplot('Position',[0.123,0.287,0.355,0.465])
if k>0
    msgbox('k输入范围出错','警告','warn')
else rlocus(sys)
    % 得出当系统稳定时K的取值范围
    num=poly(z)
    den=poly(p)
    syms('x','w','k','real')
    n=poly2sym(k*num,x)
    d=poly2sym(den,x)
    f=d+n
    g=w*i
    h=compose(f,g)
    r=real(h)
    l=simplify(imag(h))
    [k,w]=solve(r,l)
    k1=sym2poly(-k)
    if min(k1)<0
        set(handles.edit_stastic,'string',0)
    else
       set(handles.edit_stastic,'string',min(k1))
   end
    set(handles.edit_stastic1,'string',max(k1))
end
% --- Executes on button press in pushbutton_quit.function pushbutton_quit_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton_quit (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)

%设置关闭窗口提示对话框button=questdlg('Do you want to close this window?',...
    'Close Operation','Yes','No','No');
if strcmp(button,'Yes')
   close
elseif strcmp(button,'No')
    disp('Canceled file operation')
end
% --- Executes during object creation, after setting all properties.function edit_stastic_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit_stastic (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_stastic_Callback(hObject, eventdata, handles)% hObject    handle to edit_stastic (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_stastic as text%        str2double(get(hObject,'String')) returns contents of edit_stastic as a double% --- Executes during object creation, after setting all properties.function edit_stastic1_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit_stastic1 (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_stastic1_Callback(hObject, eventdata, handles)% hObject    handle to edit_stastic1 (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_stastic1 as text%        str2double(get(hObject,'String')) returns contents of edit_stastic1 as a double

⌨️ 快捷键说明

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