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

📄 ninteger.m

📁 国外人编写的一个分数阶系统的控制工具箱
💻 M
📖 第 1 页 / 共 3 页
字号:
% 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_wh_Callback(hObject, eventdata, handles)
% hObject    handle to edit_wh (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_wh as text
%        str2double(get(hObject,'String')) returns contents of edit_wh as a double
redraw(handles);

% --- Executes during object creation, after setting all properties.
function edit_tf_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_tf (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_tf_Callback(hObject, eventdata, handles)
% hObject    handle to edit_tf (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_tf as text
%        str2double(get(hObject,'String')) returns contents of edit_tf as a double
redraw(handles);


% --- Executes on button press in pushbuttonnipid_Save.
function pushbutton_Save_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonnipid_Save (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if dcgain(handles.open_loop) == 0 & isempty(tzero(handles.open_loop)) &...
        isempty(pole(handles.open_loop))
    errordlg('There is no controller to save.', 'Error while saving', 'modal')
    return
end
name = get(handles.edit_name, 'String');
try
    eval(['global ' name]);
    eval([name ' = handles.C;']);
    evalin('base', ['global ' name]);
catch
    errordlg('The name you provided for the variable does not seem to be valid.', 'Error with the name', 'modal')
end


% --- Executes during object creation, after setting all properties.
function edit_name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_name (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 button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox1 (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 checkbox1
redraw(handles)

% --- Executes during object creation, after setting all properties.
function edit_varpoles_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_varpoles (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_varpoles_Callback(hObject, eventdata, handles)
% hObject    handle to edit_varpoles (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_varpoles as text
%        str2double(get(hObject,'String')) returns contents of edit_varpoles as a double
if get(handles.checkbox1, 'Value') == get(handles.checkbox1, 'Max')
    redraw(handles)
end

% --- Executes during object creation, after setting all properties.
function edit_varzeros_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_varzeros (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_varzeros_Callback(hObject, eventdata, handles)
% hObject    handle to edit_varzeros (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_varzeros as text
%        str2double(get(hObject,'String')) returns contents of edit_varzeros as a double
if get(handles.checkbox1, 'Value') == get(handles.checkbox1, 'Max')
    redraw(handles)
end

% --- Executes during object creation, after setting all properties.
function edit_vargain_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_vargain (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_vargain_Callback(hObject, eventdata, handles)
% hObject    handle to edit_vargain (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_vargain as text
%        str2double(get(hObject,'String')) returns contents of edit_vargain as a double
if get(handles.checkbox1, 'Value') == get(handles.checkbox1, 'Max')
    redraw(handles)
end


% --- Redraws the plots
function redraw(handles)
% handles     needed for handling everything

wl = str2double(get(handles.edit_wl, 'String'));
if isnan(wl) | wl<=0
    errordlg('Provide a valid positive real number for the lower limit of the x-axis.', 'Error with wl', 'modal')
    return
end
wh = str2double(get(handles.edit_wh, 'String'));
if isnan(wh) | wh<=0
    errordlg('Provide a valid positive real number for the upper limit of the x-axis.', 'Error with wh', 'modal')
    return
end
if wh <= wl
    errordlg('The upper limit of the x-axis should be greater than the lower.', 'Error with wl and wh', 'modal')
    return
end
tfinal = str2double(get(handles.edit_tf, 'String'));
if isnan(tfinal)
    errordlg('Provide a valid real number for the final time instant.', 'Error with tf', 'modal')
    return
end
plot_type = get(handles.popupmenu1, 'Value');
switch plot_type
    case 1 % Bode diagram
        axes(handles.plot)
        plot(0) % this is for clearing whatever might appear behind in axes plot
        set(handles.plot, 'Visible', 'off');
        set(handles.plot1, 'Visible', 'on');
        set(handles.plot2, 'Visible', 'on');
        set(handles.edit_wl, 'Enable', 'on');
        set(handles.edit_wh, 'Enable', 'on');
        set(handles.edit_tf, 'Enable', 'off');
    case {2, 3} % Nichols and Nyquist diagrams
        axes(handles.plot1)
        plot(0) % this is for clearing whatever might appear behind in axes1 plot
        axes(handles.plot2)
        plot(0) % this is for clearing whatever might appear behind in axes2 plot
        set(handles.plot, 'Visible', 'on');
        set(handles.plot1, 'Visible', 'off');
        set(handles.plot2, 'Visible', 'off');
        set(handles.edit_wl, 'Enable', 'on');
        set(handles.edit_wh, 'Enable', 'on');
        set(handles.edit_tf, 'Enable', 'off');
    case {4, 5} % impulse and step responses
        axes(handles.plot1)
        plot(0) % this is for clearing whatever might appear behind in axes1 plot
        axes(handles.plot2)
        plot(0) % this is for clearing whatever might appear behind in axes2 plot
        set(handles.plot, 'Visible', 'on');
        set(handles.plot1, 'Visible', 'off');
        set(handles.plot2, 'Visible', 'off');
        set(handles.edit_wl, 'Enable', 'off');
        set(handles.edit_wh, 'Enable', 'off');
        set(handles.edit_tf, 'Enable', 'on');
    case 6 % zero and pole placement
        axes(handles.plot1)
        plot(0) % this is for clearing whatever might appear behind in axes1 plot
        axes(handles.plot2)
        plot(0) % this is for clearing whatever might appear behind in axes2 plot
        set(handles.plot, 'Visible', 'on');
        set(handles.plot1, 'Visible', 'off');
        set(handles.plot2, 'Visible', 'off');
        set(handles.edit_wl, 'Enable', 'off');
        set(handles.edit_wh, 'Enable', 'off');
        set(handles.edit_tf, 'Enable', 'off');
end
% This is for the case of parameter variations being given
flag_var = (get(handles.checkbox1, 'Value') == get(handles.checkbox1, 'Max'))...
    & strcmp(get(handles.checkbox1, 'Enable'), 'on');
if flag_var
    [zeros, poles, k] = zpkdata(handles.plant, 'v');
    zeros = sort(zeros);
    poles = sort(poles);
    try
        vargain = evalin('base', get(handles.edit_vargain, 'String'));
        if any(~isreal(vargain)) | any(ischar(vargain)) |...
                size(vargain, 1) ~= 1 | size(vargain, 2) ~= 2
            errordlg('The contents of the gain variations data variable are not valid.', 'Error with vargain', 'modal')
            set(handles.checkbox1, 'Value', 0)
            flag_var = 0;
        end
    catch
        errordlg('The name you provided for the gain variations data variable does not seem to be valid.', 'Error with vargain', 'modal')
        set(handles.checkbox1, 'Value', 0)
        flag_var = 0;
    end
    try
        varzeros = evalin('base', get(handles.edit_varzeros, 'String'));
        if any(ischar(varzeros)) | size(varzeros, 1) ~= length(zeros) |...
                (size(varzeros, 2) ~= 2 & length(zeros))
            errordlg('The contents of the zero variations data variable are not valid.', 'Error with varzeros', 'modal')
            set(handles.checkbox1, 'Value', 0)
            flag_var = 0;
        end
    catch
        errordlg('The name you provided for the zero variations data variable does not seem to be valid.', 'Error with varzeros', 'modal')
        set(handles.checkbox1, 'Value', 0)
        flag_var = 0;
    end
    try
        varpoles = evalin('base', get(handles.edit_varpoles, 'String'));
        if any(ischar(varpoles)) | size(varpoles, 1) ~= length(poles) |...
                (size(varpoles, 2) ~= 2 & length(poles))
            errordlg('The contents of the pole variations data variable are not valid.', 'Error with varpoles', 'modal')
            set(handles.checkbox1, 'Value', 0)
            flag_var = 0;
        end
    catch
        errordlg('The name you provided for the pole variations data variable does not seem to be valid.', 'Error with varpoles', 'modal')
        set(handles.checkbox1, 'Value', 0)
        flag_var = 0;
    end
end
% Last of all, plots are drawn
if dcgain(handles.open_loop) == 0 & isempty(tzero(handles.open_loop)) &...
        isempty(pole(handles.open_loop))
    return
end
if ~flag_var % plant parameter variations were not given
    switch plot_type
        case 1 % Bode diagram
            w = logspace(log10(wl), log10(wh));
            [gain, phase] = bode(handles.open_loop, w);
            gain = 20*log10(squeeze(gain));
            phase = squeeze(phase);
            axes(handles.plot1)
            semilogx(w, gain)
            grid
            xlabel('Frequency (rad/s)')
            ylabel('Gain (dB)')
            axes(handles.plot2)
            semilogx(w, phase)
            grid
            ylabel('Phase (degrees)')
        case 2 % Nichols diagram
            w = logspace(log10(wl), log10(wh));
            [gain, phase] = bode(handles.open_loop, w);
            gain = 20*log10(squeeze(gain));
            phase = squeeze(phase);
            axes(handles.plot)
            plot(phase, gain)
            ngrid
            xlabel('Phase (degrees)')
            ylabel('Gain (dB)')
        case 3 % Nyquist diagram
            w = logspace(log10(wl), log10(wh));
            response = squeeze(freqresp(handles.open_loop, w));
            axes(handles.plot)
            plot(real(response), imag(response), -1, 0, 'r.')
            grid
            xlabel('Real')
            ylabel('Imaginary')
        case 4 % impulse response
            [out, t] = impulse(handles.open_loop, tfinal);
            axes(handles.plot)
            plot(t, out)
            grid
            xlabel('Time (s)')
            ylabel('Impulse response')
        case 5 % step response
            [out, t] = step(handles.open_loop, tfinal);
            axes(handles.plot)
            plot(t, out)
            grid
            xlabel('Time (s)')

⌨️ 快捷键说明

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