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

📄 rescal.m

📁 matlab GUI编写的LM317电阻选择计算软件
💻 M
字号:
function varargout = ResCal(varargin)
% RESCAL M-file for ResCal.fig
%      RESCAL, by itself, creates a new RESCAL or raises the existing
%      singleton*.
%
%      H = RESCAL returns the handle to a new RESCAL or the handle to
%      the existing singleton*.
%
%      RESCAL('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in RESCAL.M with the given input arguments.
%
%      RESCAL('Property','Value',...) creates a new RESCAL or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before ResCal_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to ResCal_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 ResCal

% Last Modified by GUIDE v2.5 20-Nov-2007 09:51:41

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ResCal_OpeningFcn, ...
                   'gui_OutputFcn',  @ResCal_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 ResCal is made visible.
function ResCal_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 ResCal (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ResCal wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = ResCal_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global val
global r1
global r2
global uo
clc
uo=str2double(get(handles.edit1,'String'));
r1=str2double(get(handles.edit2,'String'));
r2=str2double(get(handles.edit3,'String'));
popup_sel_index = get(handles.popupmenu1, 'Value');
switch popup_sel_index
    case 1     
        %only specifying Uo,random r1 and r2
        set(handles.edit1,'Enable','on');
        set(handles.edit2,'Enable','on');
        set(handles.edit3,'Enable','on');
        set(handles.edit2,'Enable','off');
        set(handles.edit3,'Enable','off');
     if isnumeric(uo) & ...
        uo >= 1.25 & ...
        uo <= 37
        guidata(hObject,handles); % store the changes
        r1 = random('unif',20,500,1,1);r1=round(r1);
        set(handles.edit2,'string',['',num2str(r1),'ŷķ']);
        r2=(uo/1.25-1)*r1;
        r2=round(r2);
        set(handles.edit3,'string',['',num2str(r2),'ŷķ']);
    else
    msgbox('Uo should be a number between 1.25V and 37V')
    end
    case 2
        set(handles.edit1,'Enable','on');
        set(handles.edit2,'Enable','on');
        set(handles.edit3,'Enable','on');
        set(handles.edit3,'Enable','off');
    if isnumeric(uo) & ...
        uo >= 1.25 & ...
        uo <= 37 & ...
        isnumeric(r1) & ...
        r1>0
        guidata(hObject,handles); % store the changes
        set(handles.edit2,'string',['',num2str(r1),'ŷķ']);
        r2=(uo/1.25-1)*r1;
        r2=round(r2);
        set(handles.edit3,'string',['',num2str(r2),'ŷķ']);
    else
    msgbox('Uo should be a number between 1.25V and 37V,R1 should be a integer')
    end
    case 3
        set(handles.edit1,'Enable','on');
        set(handles.edit2,'Enable','on');
        set(handles.edit3,'Enable','on');
        set(handles.edit2,'Enable','off');
    if isnumeric(uo) & ...
        uo >= 1.25 & ...
        uo <= 37 & ...
        isnumeric(r2) & ...
        r2>0
        guidata(hObject,handles); % store the changes
        set(handles.edit3,'string',['',num2str(r2),'ŷķ']);
        r1=r2/(uo/1.25-1);
        r1=round(r1);
        set(handles.edit2,'string',['',num2str(r1),'ŷķ']);
    else
    msgbox('Uo should be a number between 1.25V and 37V,R2 should be integer')
    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)
set(handles.edit1,'string',num2str(0));
set(handles.edit2,'string',['',num2str(0),'ŷķ']);
set(handles.edit3,'string',['',num2str(0),'ŷķ']);
set(handles.edit2,'Enable','off');
set(handles.edit3,'Enable','off');


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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes during object creation, after setting all properties.
function axes2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to axes2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes2
Image_cir=imread('317.jpg'); 
image(Image_cir);


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton1.
function pushbutton1_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function calc_Callback(hObject, eventdata, handles)
% hObject    handle to calc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --- 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
if (get(hObject,'Value') == get(hObject,'Max'))
    % then rsdio button is selected-take approriate action
    set(handles.radiobutton2,'Value','Max')
else
    % radio button is not selected-take approriate action
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




% --- 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
popup_sel_index = get(handles.popupmenu1, 'Value');
switch popup_sel_index
    case 1     
        set(handles.edit1,'Enable','on');
        set(handles.edit2,'Enable','on');
        set(handles.edit3,'Enable','on');
        set(handles.edit2,'Enable','off');
        set(handles.edit3,'Enable','off');
    case 2
        set(handles.edit1,'Enable','on');
        set(handles.edit2,'Enable','on');
        set(handles.edit3,'Enable','on');
        set(handles.edit3,'Enable','off');
    case 3
        set(handles.edit1,'Enable','on');
        set(handles.edit2,'Enable','on');
        set(handles.edit3,'Enable','on');
        set(handles.edit2,'Enable','off');
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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

set(hObject, 'String', {'Specifying Uo Only', 'Specifying Uo and R1', 'Specifying Uo and R2'});



function 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 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end






⌨️ 快捷键说明

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