📄 ninteger.m
字号:
function varargout = ninteger(varargin)
% NINTEGER M-file for ninteger.fig
% NINTEGER, by itself, creates a new NINTEGER or raises the existing
% singleton*.
%
% H = NINTEGER returns the handle to a new NINTEGER or the handle to
% the existing singleton*.
%
% NINTEGER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in NINTEGER.M with the given input arguments.
%
% NINTEGER('Property','Value',...) creates a new NINTEGER or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ninteger_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ninteger_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 ninteger
% Last Modified by GUIDE v2.5 05-Aug-2005 18:33:21
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ninteger_OpeningFcn, ...
'gui_OutputFcn', @ninteger_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 ninteger is made visible.
function ninteger_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 ninteger (see VARARGIN)
% Choose default command line output for ninteger
handles.output = hObject;
% UIWAIT makes ninteger wait for user response (see UIRESUME)
% uiwait(handles.figure1);
handles.C = tf(0);
handles.plant = tf(0);
handles.open_loop = handles.C;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = ninteger_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 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
button_state = get(hObject, 'Value');
if button_state == get(hObject, 'Max')
handles.plant = tf(0);
handles.open_loop = handles.C;
set(handles.radiobutton2, 'Value', 0);
set(handles.checkbox1, 'Enable', 'off');
set(handles.edit_vargain, 'Enable', 'off');
set(handles.edit_varzeros, 'Enable', 'off');
set(handles.edit_varpoles, 'Enable', 'off');
guidata(hObject, handles)
redraw(handles);
elseif button_state == get(hObject,'Min')
try
handles.plant = evalin('base', get(handles.edit_plant, 'String'));
handles.open_loop = handles.C * handles.plant;
set(handles.radiobutton2, 'Value', 1);
set(handles.checkbox1, 'Enable', 'on');
set(handles.edit_vargain, 'Enable', 'on');
set(handles.edit_varzeros, 'Enable', 'on');
set(handles.edit_varpoles, 'Enable', 'on');
guidata(hObject, handles)
redraw(handles);
catch
handles.plant = tf(0);
handles.open_loop = handles.C;
set(handles.radiobutton2, 'Value', 0);
set(hObject, 'Value', 1);
set(handles.checkbox1, 'Enable', 'off');
set(handles.edit_vargain, 'Enable', 'off');
set(handles.edit_varzeros, 'Enable', 'off');
set(handles.edit_varpoles, 'Enable', 'off');
guidata(hObject, handles)
errordlg(['Provide a valid LTI plant with the same sampling',...
' time of the controller.'], 'Error with the plant', 'modal')
end
end
% --- 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
button_state = get(hObject, 'Value');
if button_state == get(hObject, 'Max')
try
handles.plant = evalin('base', get(handles.edit_plant, 'String'));
handles.open_loop = handles.C * handles.plant;
set(handles.radiobutton1, 'Value', 0);
set(handles.checkbox1, 'Enable', 'on');
set(handles.edit_vargain, 'Enable', 'on');
set(handles.edit_varzeros, 'Enable', 'on');
set(handles.edit_varpoles, 'Enable', 'on');
guidata(hObject, handles)
redraw(handles);
catch
handles.plant = tf(0);
handles.open_loop = handles.C;
set(handles.radiobutton1, 'Value', 1);
set(hObject, 'Value', 0);
set(handles.checkbox1, 'Enable', 'off');
set(handles.edit_vargain, 'Enable', 'off');
set(handles.edit_varzeros, 'Enable', 'off');
set(handles.edit_varpoles, 'Enable', 'off');
guidata(hObject, handles)
errordlg(['Provide a valid LTI plant with the same sampling',...
' time of the controller.'], 'Error with the plant', 'modal')
end
elseif button_state == get(hObject,'Min')
handles.plant = tf(0);
handles.open_loop = handles.C;
set(handles.radiobutton1, 'Value', 1);
set(handles.checkbox1, 'Enable', 'off');
set(handles.edit_vargain, 'Enable', 'off');
set(handles.edit_varzeros, 'Enable', 'off');
set(handles.edit_varpoles, 'Enable', 'off');
guidata(hObject, handles)
redraw(handles);
end
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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 popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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 popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
redraw(handles);
% --- Executes during object creation, after setting all properties.
function edit_plant_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_plant (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 edit_plant_Callback(hObject, eventdata, handles)
% hObject handle to edit_plant (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_plant as text
% str2double(get(hObject,'String')) returns contents of edit_plant as a double
if get(handles.radiobutton2, 'Value') == get(handles.radiobutton2, 'Max')
try
handles.plant = evalin('base', get(handles.edit_plant, 'String'));
handles.open_loop = handles.C * handles.plant;
guidata(hObject, handles)
redraw(handles);
catch
handles.plant = tf(0);
handles.open_loop = handles.C;
set(handles.radiobutton1, 'Value', 1);
set(handles.radiobutton2, 'Value', 0);
set(handles.checkbox1, 'Enable', 'off');
set(handles.edit_vargain, 'Enable', 'off');
set(handles.edit_varzeros, 'Enable', 'off');
set(handles.edit_varpoles, 'Enable', 'off');
guidata(hObject, handles)
redraw(handles);
errordlg(['Provide a valid LTI plant with the same sampling',...
' time of the controller.'], 'Error with the plant', 'modal')
end
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
temp = crone2Gui; % temp is used so that tf(0) is rejected and handles.C retained
if dcgain(temp) ~= 0 | ~isempty(tzero(temp)) | ~isempty(pole(temp))
handles.C = temp;
handles.open_loop = handles.C;
% Update handles structure
guidata(hObject, handles);
% this is for handling the case of there being a plant
edit_plant_Callback(hObject, eventdata, handles);
redraw(handles);
end
catch
ninteger
errordlg('There was an error while building the controller.', 'Error', 'modal')
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)
try
[w, gainC, phaseC, strings, G] = crone3Gui1;
if isempty(w)
return
end
temp = crone3Gui2(w, gainC, phaseC, G.Ts);
% temp is used so that tf(0) is rejected and handles.C retained
if dcgain(temp) ~= 0 | ~isempty(tzero(temp)) | ~isempty(pole(temp))
handles.C = temp;
handles.open_loop = handles.C;
set(handles.radiobutton1, 'Value', 0);
set(handles.radiobutton2, 'Value', 1);
set(handles.checkbox1, 'Enable', 'on');
set(handles.edit_vargain, 'Enable', 'on');
set(handles.edit_varzeros, 'Enable', 'on');
set(handles.edit_varpoles, 'Enable', 'on');
set(handles.checkbox1, 'Value', 1);
set(handles.edit_plant, 'String', strings.plant);
set(handles.edit_vargain, 'String', strings.vargain);
set(handles.edit_varzeros, 'String', strings.varzeros);
set(handles.edit_varpoles, 'String', strings.varpoles);
% Update handles structure
guidata(hObject, handles);
% this is for handling the plant and redrawing the plot
edit_plant_Callback(hObject, eventdata, handles);
end
catch
ninteger
errordlg('There was an error while building the controller.', 'Error', 'modal')
end
% --- Executes on button press in pushbuttonnipid.
function pushbuttonnipid_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonnipid (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
temp = nipidGui; % temp is used so that tf(0) is rejected and handles.C retained
if dcgain(temp) ~= 0 | ~isempty(tzero(temp)) | ~isempty(pole(temp))
handles.C = temp;
handles.open_loop = handles.C;
% Update handles structure
guidata(hObject, handles);
% this is for handling the case of there being a plant
edit_plant_Callback(hObject, eventdata, handles);
redraw(handles);
end
% --- Executes during object creation, after setting all properties.
function edit_wl_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_wl (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 edit_wl_Callback(hObject, eventdata, handles)
% hObject handle to edit_wl (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_wl as text
% str2double(get(hObject,'String')) returns contents of edit_wl as a double
redraw(handles);
% --- Executes during object creation, after setting all properties.
function edit_wh_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_wh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -