No BSD License  

Highlights from
GUI for Control System Design & Analysis

image thumbnail
from GUI for Control System Design & Analysis by Imtiaz Hussain
An easy to use GUI for control system analysis and design

tresponse3(varargin)
function varargout = tresponse3(varargin)
% TRESPONSE3 M-file for tresponse3.fig
%      TRESPONSE3, by itself, creates a new TRESPONSE3 or raises the existing
%      singleton*.
%
%      H = TRESPONSE3 returns the handle to a new TRESPONSE3 or the handle to
%      the existing singleton*.
%
%      TRESPONSE3('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TRESPONSE3.M with the given input arguments.
%
%      TRESPONSE3('Property','Value',...) creates a new TRESPONSE3 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before tresponse3_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to tresponse3_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

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help tresponse3

% Last Modified by GUIDE v2.5 03-Jul-2007 21:49:08

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @tresponse3_OpeningFcn, ...
                   'gui_OutputFcn',  @tresponse3_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(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 tresponse3 is made visible.
function tresponse3_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 tresponse3 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = tresponse3_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 on button press in togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject    handle to togglebutton1 (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 togglebutton1

stat=get(handles.togglebutton1,'value');
if stat==1
    grid on
elseif stat==0
    grid off
end


function 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 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'));
end



function 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 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'));
end


% --- Executes on selection change in listbox2.
function listbox2_Callback(hObject, eventdata, handles)
% hObject    handle to listbox2 (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 listbox2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox2

r=get(handles.listbox2,'value');
num=get(handles.edit1,'string');
den=get(handles.edit3,'string');
if num=='0' && den=='0'
    num=1;
    den=[1 2 4];
else
num=str2num(num);
den=str2num(den);
end


if  r==3
        axes(handles.axes1);
        T=0:0.1:10;
        [Y  t]=step(num,den,T);
        cla
        hold off
        plot(T,Y);
        
elseif r==4
        axes(handles.axes1);    
        t=0:0.1:10;
        [y  T]=impulse(num,den,t);
        hold off
        cla
        plot(t,y)
elseif r==5
        axes(handles.axes1);
        t=0:0.1:10;
        input=t;
        [y  T]=lsim(num,den,input,t);
        hold off
        cla
        plot(t,y)
elseif r==6
        axes(handles.axes1);
        [pol  zer]=pzmap(num,den);
        hold off
        cla
        plot(pol,'x');
        hold on
        plot(zer,'o');
        hold off
elseif  r==7
        axes(handles.axes1);
        [R K]=rlocus(num,den);  
        hold off
        cla
        plot(R)
elseif  r==8
        axes(handles.axes1);
        w=0.1:0.1:10;
        [Mag Ph]=bode(num,den,w);  
        hold off
        cla
        semilogx(w,Mag)
elseif  r==9
        axes(handles.axes1);
        w=0.1:0.1:10;
        [Mag Ph]=bode(num,den,w);  
        hold off
        cla
        semilogx(w,Ph)
end
% --- Executes during object creation, after setting all properties.
function listbox2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox 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


Contact us at files@mathworks.com