📄 zhang2.m
字号:
function varargout = zhang2(varargin)
% ZHANG2 M-file for zhang2.fig
% ZHANG2, by itself, creates a new ZHANG2 or raises the existing
% singleton*.
%
% H = ZHANG2 returns the handle to a new ZHANG2 or the handle to
% the existing singleton*.
%
% ZHANG2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ZHANG2.M with the given input arguments.
%
% ZHANG2('Property','Value',...) creates a new ZHANG2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before zhang2_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to zhang2_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 zhang2
% Last Modified by GUIDE v2.5 12-Jun-2005 19:01:01
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @zhang2_OpeningFcn, ...
'gui_OutputFcn', @zhang2_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 zhang2 is made visible.
function zhang2_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 zhang2 (see VARARGIN)
% Choose default command line output for zhang2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes zhang2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = zhang2_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 during object creation, after setting all properties.function edit4_CreateFcn(hObject, eventdata, handles)% hObject handle to edit4 (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 edit4_Callback(hObject, eventdata, handles)% hObject handle to edit4 (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 edit4 as text% str2double(get(hObject,'String')) returns contents of edit4 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)
%获得输入数值
A=str2num(get(handles.edit1,'string'))
B=str2num(get(handles.edit2,'string'))
C=str2num(get(handles.edit3,'string'))
D=str2num(get(handles.edit4,'string'))
sys=ss(A,B,C,D)
[num,den]=ss2tf(A,B,C,D)
%绘制bode图
w=logspace(-1,2)
[m1,p1]=bode(num,den,w)
subplot('position',[0.44,0.7,0.48,0.2])
semilogx(w,20*log10(m1))
title('开环bode图')
ylabel('幅值')
grid on
subplot('position',[0.44,0.42,0.48,0.2])
semilogx(w,p1)
xlabel('频率')
ylabel('相角')
grid on
%计算频域特性指标并显示
[Gm,Pm,Wcg,Wcp]=margin(sys)
set(handles.edit5,'string',Gm)
set(handles.edit6,'string',Pm)
set(handles.edit7,'string',Wcg)
set(handles.edit8,'string',Wcp)
set(handles.edit5,'visible','on')
set(handles.edit6,'visible','on')
set(handles.edit7,'visible','on')
set(handles.edit8,'visible','on')
set(handles.text9,'visible','on')
set(handles.text10,'visible','on')
set(handles.text11,'visible','on')
set(handles.text12,'visible','on')
set(handles.pushbutton5,'visible','on')
set(handles.pushbutton8,'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)
%获得输入数值 A=str2num(get(handles.edit1,'string'))
B=str2num(get(handles.edit2,'string'))
C=str2num(get(handles.edit3,'string'))
D=str2num(get(handles.edit4,'string'))
sys=ss(A,B,C,D)
%将状态空间模型转换为传递函数模型
[numo,deno]=ss2tf(A,B,C,D)
numc=numo
n=poly2sym(numo)
d=poly2sym(deno)
denc=sym2poly(n+d)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -