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

📄 lab01.m

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

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

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

% Update handles structure
guidata(hObject, handles);

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

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

% --- Outputs from this function are returned to the command line.
function varargout = lab01_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_num_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit_num (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_num_Callback(hObject, eventdata, handles)% hObject    handle to edit_num (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_num as text%        str2double(get(hObject,'String')) returns contents of edit_num as a double% --- Executes during object creation, after setting all properties.function edit_den_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit_den (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_den_Callback(hObject, eventdata, handles)% hObject    handle to edit_den (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_den as text%        str2double(get(hObject,'String')) returns contents of edit_den 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)

%接受分子分母在编辑框中的数值并画根轨迹图num=str2num(get(handles.edit_num,'string'))
den=str2num(get(handles.edit_den,'string'))
sys=tf(num,den)
subplot('Position',[0.123,0.267,0.355,0.422])
n=num(1,1)
d=den(1,1)
if n<0&d>0||n>0&d<0
    msgbox('分子输入范围出错(最高次系数应为正)','警告', 'warn')
else rlocus(sys)
    %得出系统稳定时K的取值范围
    syms('x','w','k','real')               
    n=poly2sym(k*num,x)
    d=poly2sym(den,x)
    f=n+d
    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
if max(k1)<=0
    set(handles.edit_stastic1,'string',inf)
else
    set(handles.edit_stastic1,'string',max(k1))
end

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 + -