📄 crone2gui.m
字号:
function varargout = crone2Gui(varargin)
% CRONE2GUI M-file for crone2Gui.fig
% CRONE2GUI, by itself, creates a new CRONE2GUI or raises the existing
% singleton*.
%
% H = CRONE2GUI returns the handle to a new CRONE2GUI or the handle to
% the existing singleton*.
%
% CRONE2GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CRONE2GUI.M with the given input arguments.
%
% CRONE2GUI('Property','Value',...) creates a new CRONE2GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before crone2Gui_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to crone2Gui_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 crone2Gui
% Last Modified by GUIDE v2.5 15-Sep-2003 09:54:25
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @crone2Gui_OpeningFcn, ...
'gui_OutputFcn', @crone2Gui_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 crone2Gui is made visible.
function crone2Gui_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 crone2Gui (see VARARGIN)
% Choose default command line output for crone2Gui
handles.output = tf(0);
handles.w = [];
handles.plant = tf(0);
handles.gain = [];
handles.phase = [];
% Update handles structure
guidata(hObject, handles);
% legends are added
axes(handles.axes_gain)
xlabel('Frequency (rad/s)')
ylabel('Gain (dB)')
axes(handles.axes_phase)
ylabel('Phase (degrees)')
% UIWAIT makes crone2Gui wait for user response (see UIRESUME)
uiwait(handles.crone2Gui);
% --- Outputs from this function are returned to the command line.
function varargout = crone2Gui_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
if ~isempty(handles)
varargout{1} = handles.output;
delete(handles.crone2Gui);
else
varargout{1} = tf(0);
end
% --- Executes on button press in radiobutton_Gain_data.function radiobutton_Gain_data_Callback(hObject, eventdata, handles)% hObject handle to radiobutton_Gain_data (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 radiobutton_Gain_databutton_state = get(hObject, 'Value');
if button_state == get(hObject, 'Max')
set(handles.radiobutton_Unit_gain, 'Value', 0);
try
handles.gain = evalin('base', get(handles.edit_gain, 'String'));
if any(~isreal(handles.gain)) | any(ischar(handles.gain))
set(handles.radiobutton_Unit_gain, 'Value', 1);
set(hObject, 'Value', 0);
errordlg('Gains (in dB) must be positive.', 'Error with the gain', 'modal')
end
if size(handles.gain, 2)>1 | length(handles.gain)~=length(handles.w)
set(handles.radiobutton_Unit_gain, 'Value', 1);
set(hObject, 'Value', 0);
errordlg('The list of gains must be a column vector of positive real numbers with the same size of the list of frequencies.', 'Error with the gain', 'modal')
end
catch
set(handles.radiobutton_Unit_gain, 'Value', 1);
set(hObject, 'Value', 0);
errordlg('The name you provided for the gain data variable does not seem to be valid, or else its contents are not.', 'Error with the name', 'modal')
end
else
set(handles.radiobutton_Unit_gain, 'Value', 1);
end
guidata(hObject, handles);
redraw(handles)
% --- Executes on button press in radiobutton_Unit_gain.function radiobutton_Unit_gain_Callback(hObject, eventdata, handles)% hObject handle to radiobutton_Unit_gain (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 radiobutton_Unit_gainbutton_state = get(hObject, 'Value');
if button_state == get(hObject, 'Max')
set(handles.radiobutton_Gain_data, 'Value', 0);
else
set(handles.radiobutton_Gain_data, 'Value', 1);
try
handles.gain = evalin('base', get(handles.edit_gain, 'String'));
if any(~isreal(handles.gain)) | any(ischar(handles.gain))
set(handles.radiobutton_Gain_data, 'Value', 0);
set(hObject, 'Value', 1);
errordlg('Gains (in dB) must be positive.', 'Error with the gain', 'modal')
end
if size(handles.gain, 2)>1
set(handles.radiobutton_Gain_data, 'Value', 0);
set(hObject, 'Value', 1);
errordlg('The list of gains must be a column vector of positive real numbers.', 'Error with the gain', 'modal')
end
catch
set(handles.radiobutton_Gain_data, 'Value', 0);
set(hObject, 'Value', 1);
errordlg('The name you provided for the gain data variable does not seem to be valid, or else its contents are not.', 'Error with the name', 'modal')
end
end
guidata(hObject, handles);
redraw(handles)
% --- Executes on button press in radiobutton_continuous.function radiobutton_continuous_Callback(hObject, eventdata, handles)% hObject handle to radiobutton_continuous (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 radiobutton_continuousbutton_state = get(hObject, 'Value');
if button_state == get(hObject, 'Max')
set(handles.radiobutton_Ts, 'Value', 0);
elseif button_state == get(hObject,'Min')
set(handles.radiobutton_Ts, 'Value', 1);
end
% --- Executes on button press in radiobutton_Ts.function radiobutton_Ts_Callback(hObject, eventdata, handles)% hObject handle to radiobutton_Ts (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 radiobutton_Tsbutton_state = get(hObject, 'Value');
if button_state == get(hObject, 'Max')
set(handles.radiobutton_continuous, 'Value', 0);
elseif button_state == get(hObject,'Min')
set(handles.radiobutton_continuous, 'Value', 1);
end
% --- Executes on button press in pushbutton_OK.function pushbutton_OK_Callback(hObject, eventdata, handles)% hObject handle to pushbutton_OK (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)if isempty(handles.w)
errordlg('You must provide a valid list of frequencies.', 'Error with w', 'modal')
return
end
if isempty(handles.phase)
errordlg(['You must provide a phase behaviour to mimic, either by inputting'...
'a list of phases or by giving a plant to complement.'], 'Error with the phase', 'modal')
return
end
n = str2double(get(handles.edit_n, 'String'));
if isnan(n) | n<=0 | ~isinteger(n)
errordlg('Specify the number of zeros and poles with a valid positive integer number.', 'Error with n', 'modal')
return
end
if get(handles.radiobutton_Ts, 'Value') == get(handles.radiobutton_Ts, 'Max')
Ts = str2double(get(handles.edit_Ts, 'String'));
if isnan(Ts) | Ts<=0
errordlg('Provide a valid positive real number for the sampling time.', 'Error with Ts', 'modal')
return
end
else
Ts = 0;
end
if get(handles.radiobutton_Gain_data, 'Value') ==...
get(handles.radiobutton_Gain_data, 'Max')
if Ts
handles.output = crone2z(handles.w, handles.gain, handles.phase, n, Ts);
else
handles.output = crone2(handles.w, handles.gain, handles.phase, n);
end
else
w1 = str2double(get(handles.edit_w1, 'String'));
if isnan(w1) | n<=0
errordlg('Provide a valid positive real number for the unit gain frequency.', 'Error with w1', 'modal')
return
end
if Ts
handles.output = crone2z(handles.w, [], handles.phase, n, Ts, w1);
else
handles.output = crone2(handles.w, [], handles.phase, n, w1);
end
end
guidata(hObject, handles);
uiresume
% --- Executes on button press in pushbutton_Cancel.function pushbutton_Cancel_Callback(hObject, eventdata, handles)% hObject handle to pushbutton_Cancel (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)uiresume % this handles the closing of the function
% --- Executes during object creation, after setting all properties.function edit_Ts_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_Ts (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 during object creation, after setting all properties.function edit_w1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_w1 (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 during object creation, after setting all properties.function edit_gain_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_gain (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_gain_Callback(hObject, eventdata, handles)% hObject handle to edit_gain (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_gain as text% str2double(get(hObject,'String')) returns contents of edit_gain as a doubleif get(handles.radiobutton_Gain_data, 'Value') ==...
get(handles.radiobutton_Gain_data, 'Max')
try
handles.gain = evalin('base', get(handles.edit_gain, 'String'));
if any(~isreal(handles.gain)) | any(ischar(handles.gain))
set(handles.radiobutton_Unit_gain, 'Value', 1);
set(handles.radiobutton_Gain_data, 'Value', 0);
errordlg('Gains (in dB) must be real.', 'Error with the gain', 'modal')
end
if size(handles.gain, 2)>1 | length(handles.gain)~=length(handles.w)
set(handles.radiobutton_Unit_gain, 'Value', 1);
set(handles.radiobutton_Gain_data, 'Value', 0);
errordlg('The list of gains must be a column vector of real numbers with the same size of the list of frequencies.', 'Error with the gain', 'modal')
end
catch
set(handles.radiobutton_Unit_gain, 'Value', 1);
set(handles.radiobutton_Gain_data, 'Value', 0);
errordlg('The name you provided for the gain data variable does not seem to be valid, or else its contents are not.', 'Error with the name', 'modal')
end
redraw(handles)
end
% --- Executes on button press in radiobutton_phase.function radiobutton_phase_Callback(hObject, eventdata, handles)% hObject handle to radiobutton_phase (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 radiobutton_phasebutton_state = get(hObject, 'Value');
if button_state == get(hObject, 'Max')
set(handles.radiobutton_complement, 'Value', 0);
try
handles.phase = evalin('base', get(handles.edit_phase, 'String'));
if any(~isreal(handles.phase)) | any(ischar(handles.phase))
set(handles.radiobutton_complement, 'Value', 1);
set(hObject, 'Value', 0);
errordlg('Phases (in degrees) must be real.', 'Error with the phase', 'modal')
edit_plant_Callback(hObject, eventdata, handles);
end
if size(handles.phase, 2)>1 | length(handles.phase)~=length(handles.w)
set(handles.radiobutton_complement, 'Value', 1);
set(hObject, 'Value', 0);
errordlg('The list of phases must be a column vector of real numbers with the same size of the list of frequencies.', 'Error with the phase', 'modal')
edit_plant_Callback(hObject, eventdata, handles);
end
catch
set(handles.radiobutton_complement, 'Value', 1);
set(hObject, 'Value', 0);
errordlg('The name you provided for the phase data variable does not seem to be valid, or else its contents are not.', 'Error with the name', 'modal')
edit_plant_Callback(hObject, eventdata, handles);
end
else
set(handles.radiobutton_complement, 'Value', 1);
end
guidata(hObject, handles);
redraw(handles)% --- Executes on button press in radiobutton_complement.function radiobutton_complement_Callback(hObject, eventdata, handles)% hObject handle to radiobutton_complement (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -