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

📄 stepdelay.m

📁 经典控制理论MATLAB-GUI设计
💻 M
字号:
function varargout = stepdelay(varargin)
% STEPDELAY M-file for stepdelay.fig
%      STEPDELAY, by itself, creates a new STEPDELAY or raises the existing
%      singleton*.
%
%      H = STEPDELAY returns the handle to a new STEPDELAY or the handle to
%      the existing singleton*.
%
%      STEPDELAY('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in STEPDELAY.M with the given input arguments.
%
%      STEPDELAY('Property','Value',...) creates a new STEPDELAY or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before stepdelay_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to stepdelay_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 stepdelay

% Last Modified by GUIDE v2.5 01-May-2005 11:54:13

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @stepdelay_OpeningFcn, ...
                   'gui_OutputFcn',  @stepdelay_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 stepdelay is made visible.
function stepdelay_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 stepdelay (see VARARGIN)
Handle_text = findobj('Tag','layoutedit');
    %当没有选择要进行何种分析时,文本窗口中给出如下提示。
    Str(1) = {'在右边选择响的系统模型'};
    Str(2) = {'然后输入参数'};
    Str(3) = {'上图将显示分结果'};
   
    set(Handle_text,'String',Str);
% Choose default command line output for stepdelay
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = stepdelay_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 layoutedit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to layoutedit (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'));
end



function layoutedit_Callback(hObject, eventdata, handles)
% hObject    handle to layoutedit (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 layoutedit as text
%        str2double(get(hObject,'String')) returns contents of layoutedit as a double


% --- Executes during object creation, after setting all properties.
function passorzp_CreateFcn(hObject, eventdata, handles)
% hObject    handle to passorzp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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'));
end


% --- Executes on selection change in passorzp.
function passorzp_Callback(hObject, eventdata, handles)
% hObject    handle to passorzp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns passorzp contents as cell array
%        contents{get(hObject,'Value')} returns selected item from passorzp


% --- Executes during object creation, after setting all properties.
function clooporopen_CreateFcn(hObject, eventdata, handles)
% hObject    handle to clooporopen (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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'));
end


% --- Executes on selection change in clooporopen.
function clooporopen_Callback(hObject, eventdata, handles)
% hObject    handle to clooporopen (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns clooporopen contents as cell array
%        contents{get(hObject,'Value')} returns selected item from clooporopen


% --- Executes during object creation, after setting all properties.
function numorzero_CreateFcn(hObject, eventdata, handles)
% hObject    handle to numorzero (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'));
end



function numorzero_Callback(hObject, eventdata, handles)
% hObject    handle to numorzero (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 numorzero as text
%        str2double(get(hObject,'String')) returns contents of numorzero as a double


% --- Executes during object creation, after setting all properties.
function denorp_CreateFcn(hObject, eventdata, handles)
% hObject    handle to denorp (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'));
end



function denorp_Callback(hObject, eventdata, handles)
% hObject    handle to denorp (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 denorp as text
%        str2double(get(hObject,'String')) returns contents of denorp as a double


% --- Executes during object creation, after setting all properties.
function kedit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to kedit (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'));
end



function kedit_Callback(hObject, eventdata, handles)
% hObject    handle to kedit (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 kedit as text
%        str2double(get(hObject,'String')) returns contents of kedit as a double


% --- Executes on button press in stepdrew.
function stepdrew_Callback(hObject, eventdata, handles)
% hObject    handle to stepdrew (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

Val_Selection = get(findobj('Tag','passorzp'),'Value');
Val_clooporopen = get(findobj('Tag','clooporopen'),'Value');



%--------根据判断建立相应的模型---------
switch Val_Selection
%----获得传递函数形式的输入 ---------- 
    case 1
        Handle_numorzero    =      findobj( 'Tag','numorzero');
        Val_numzero         =      get(Handle_numorzero,'String');
        Val_num             =      str2num(Val_numzero);
        
        Handle_denorp       =      findobj('Tag','denorp');
        Val_denp            =      get(Handle_denorp,'String');
        Val_den             =      str2num(Val_denp);
        
        Handle_kedit        =      findobj('Tag','kedit');
        Val_kedit           =      get (Handle_kedit,'String');
        %Val_k               =      str2num(Val_kedit);
        
        num                 =      Val_num%*Val_k;
        den                 =      Val_den;
%获得零极点形式的输入 
    case 2                 
        Handle_numorzero    =      findobj( 'Tag','numorzero');
        Val_numzero         =      get (Handle_numorzero,'String');
        Val_zero            =      str2num(Val_numzero);
        
        Handle_denorp       =      findobj('Tag','denorp');
        Val_denorp          =      get(Handle_denorp,'String');
        Val_p               =      str2num(Val_denorp);
        
        Handle_kedit        =      findobj('Tag','kedit');
        Val_kedit           =      get (Handle_kedit,'String');
        Val_k               =      str2num(Val_kedit);
        
        [num,den]        =      zp2tf(Val_zero,Val_p,Val_k);    
end

%------判断输入模型为开环or闭环并建立相应的模型-------
if (Val_clooporopen ==2)
    [numc,denc] = cloop(num,den);
    sys = tf(numc,denc);
    [z,p,k] = tf2zp(numc,denc);
else 
    numc = num;
    denc = den;
    sys = tf(numc,denc);
    [z,p,k] = tf2zp(numc,denc);
end
figure(1)
hold on
step(sys);
title('阶跃响应图');
flag =real(p);
%当系统在s坐标平面的右半侧有极点时,系统不稳定。
if (find(flag>0)~=0)
    Handle_text = findobj('Tag','layoutedit');
    Str(1) = {''};
    Str(2) = {'该系统不稳定'};
    set (Handle_text,'String',Str);
 %当系统有0极点是,该系统处于临届稳定状态。    
elseif (find(flag==0)~=0)
    Handle_text = findobj('Tag','layoutedit');
    Str(1) = {''};
    Str(2) = {'该系统处于临届稳定状态'};
    set (Handle_text,'String',Str);
%当该系统的极点全部位于s平面的左半面时,该系统处于稳定状态。    
else
    Handle_text = findobj('Tag','layoutedit');
    Str(1) = {'该系统稳定'};
%该系统稳定,并给出相应的频域参数。    
    [M,P,w] = bode(sys);
    [GM,PM,wcg,wcp] = margin(M,P,w);
    Str(2) = {'该系统的幅值裕量为:'};
    Str(3) = {GM};
    Str(4) = {'该系统的相位裕量为:'};
    Str(5) = {PM};
    Str(6) = {'该系统的相位交界(或穿越)频率为:'};
    Str(7) = {wcg};
    Str(8) = {'该系统的增益交界频率(又称剪切频率或交界频率)为:'};
    Str(9) = {wcp};
    set(Handle_text,'String',Str);
end




% --- 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)
chaoqian

⌨️ 快捷键说明

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