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

📄 jisuanqi.m

📁 MATLAB编写的3个简易计算器程序
💻 M
字号:
function varargout = jisuanqi(varargin)


gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @jisuanqi_OpeningFcn, ...
                   'gui_OutputFcn',  @jisuanqi_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


function jisuanqi_OpeningFcn(hObject, eventdata, handles, varargin)
global statue;
h=get(handles.edit1,'String');
switch(h)
    case{'+','-','*','/'}
        statue=1;
    otherwise 
        statue=0;
end
handles.output = hObject;


guidata(hObject, handles);




function varargout = jisuanqi_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 pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
global statue;
 if (statue==1)
    
        set(handles.edit1,'String','7');
        statue=0;
 elseif (statue==0)
    h=get(handles.edit1,'String');
switch(h)
    case  '0';
    set(handles.edit1,'String','7');  
    otherwise
        str=strcat(h,'7');
            set(handles.edit1,'String',str);
end
   
          
         end   


    
      

function pushbutton4_Callback(hObject, eventdata, handles)
global statue;
 if (statue==1)
    
        set(handles.edit1,'String','4');
        statue=0;
 elseif (statue==0)
    h=get(handles.edit1,'String');
switch(h)
    case  '0';
    set(handles.edit1,'String','4');  
    otherwise
        str=strcat(h,'4');
            set(handles.edit1,'String',str);
end
   
          
         end   
% hObject    handle to pushbutton4 (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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
global statue;
 if (statue==1)
    
        set(handles.edit1,'String','1');
        statue=0;
 elseif (statue==0)
    h=get(handles.edit1,'String');
switch(h)
    case  '0';
    set(handles.edit1,'String','1');  
    otherwise
        str=strcat(h,'1');
            set(handles.edit1,'String',str);
end
   
          
         end   





function pushbutton0_Callback(hObject, eventdata, handles)
global statue;
 if (statue==1)
    
        set(handles.edit1,'String','0');
        statue=0;
 elseif (statue==0)
    h=get(handles.edit1,'String');
switch(h)
    case  '0';
    set(handles.edit1,'String','0');  
    otherwise
        str=strcat(h,'0');
            set(handles.edit1,'String',str);
end
   
          
         end   
% hObject    handle to pushbutton0 (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 pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
global statue;
 if (statue==1)
    
        set(handles.edit1,'String','8');
        statue=0;
 elseif (statue==0)
    h=get(handles.edit1,'String');
switch(h)
    case  '0';
    set(handles.edit1,'String','8');  
    otherwise
        str=strcat(h,'8');
            set(handles.edit1,'String',str);
end
   
          
         end   

% hObject    handle to pushbutton8 (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 pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
global statue;
 if (statue==1)
    
        set(handles.edit1,'String','5');
        statue=0;
 elseif (statue==0)
    h=get(handles.edit1,'String');
switch(h)
    case  '0';
    set(handles.edit1,'String','5');  
    otherwise
        str=strcat(h,'5');
            set(handles.edit1,'String',str);
end
   
          
         end   % hObject    handle to pushbutton5 (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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
global statue;
 if (statue==1)
    
        set(handles.edit1,'String','2');
        statue=0;
 elseif (statue==0)
    h=get(handles.edit1,'String');
switch(h)
    case  '0';
    set(handles.edit1,'String','2');  
    otherwise
        str=strcat(h,'2');
            set(handles.edit1,'String',str);
end
   
          
         end   
% 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)


% --- Executes on button press in jiahuojian.
function jiahuojian_Callback(hObject, eventdata, handles)
% hObject    handle to jiahuojian (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 pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
global statue;
 if (statue==1)
    
        set(handles.edit1,'String','6');
        statue=0;
 elseif (statue==0)
    h=get(handles.edit1,'String');
switch(h)
    case  '0';
    set(handles.edit1,'String','6');  
    otherwise
        str=strcat(h,'6');
            set(handles.edit1,'String',str);
end
   
          
         end   
% hObject    handle to pushbutton6 (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 pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
global statue;
 if (statue==1)
    
        set(handles.edit1,'String','9');
        statue=0;
 elseif (statue==0)
    h=get(handles.edit1,'String');
switch(h)
    case  '0';
    set(handles.edit1,'String','9');  
    otherwise
        str=strcat(h,'9');
            set(handles.edit1,'String',str);
end
   
          
         end   
% hObject    handle to pushbutton9 (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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
global statue;
 if (statue==1)
    
        set(handles.edit1,'String','3');
        statue=0;
 elseif (statue==0)
    h=get(handles.edit1,'String');
switch(h)
    case  '0';
    set(handles.edit1,'String','3');  
    otherwise
        str=strcat(h,'3');
            set(handles.edit1,'String',str);
end
   
          
         end   
% 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)


% --- Executes on button press in xiaoshudian.
function xiaoshudian_Callback(hObject, eventdata, handles)
global statue;
if(statue==0)

str=strcat(get(handles.edit1,'String'),'.');
set(handles.edit1,'String',str);
end
    
% hObject    handle to xiaoshudian (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 chuhao.
function chuhao_Callback(hObject, eventdata, handles)
global statue;
if (statue==0)
statue=1;
global val1;
val1=str2num(get(handles.edit1,'String'));
end
global op;
op='/';

set(handles.edit1,'String','/');

% hObject    handle to chuhao (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 chenghao.
function chenghao_Callback(hObject, eventdata, handles)

global op;
op='*';
global statue;
if (statue==0)
global val2;
val2=str2num(get(handles.edit1,'String'));
statue=1;
end
set(handles.edit1,'String','*');
% hObject    handle to chenghao (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 jianhao.
function jianhao_Callback(hObject, eventdata, handles)

global op;
op='-';
global statue;
if(statue==0)
global val3;
val3=str2num(get(handles.edit1,'String'));
statue=1;
end
 set(handles.edit1,'String','-');
% hObject    handle to jianhao (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 jiahao.
function jiahao_Callback(hObject, eventdata, handles)

global op;
op='+';
global statue;
if (statue==0)
    global val4;
    val4=str2num(get(handles.edit1,'String'));

statue=1;
end
set(handles.edit1,'String','+');



function duishu_Callback(hObject, eventdata, handles)
global statue;
if (statue==0)
    result=log(str2num(get(handles.edit1,'String')));
    set(handles.edit1,'String',num2str(result));
end
% hObject    handle to duishu (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 kaifang.
function kaifang_Callback(hObject, eventdata, handles)
global statue;
if (statue==0)
result=sqrt(str2num(get(handles.edit1,'String')));
set(handles.edit1,'String',num2str(result));
end
% hObject    handle to kaifang (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 qiumi.
function qiumi_Callback(hObject, eventdata, handles)
global statue;
if (statue==0)
    global op;
    op='^'
    global val6;
 val6=str2num(get(handles.edit1,'String'));
 
 statue=1;
end
set(handles.edit1,'String','^');
% hObject    handle to qiumi (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 dengyu.
function dengyu_Callback(hObject, eventdata, handles)
global val1;
    global val2;
    global val3;
    global val4;
    global val5;
    global val6;
    
val5=str2num(get(handles.edit1,'String'));

global op;
switch (op)
    
    case '+';
       
        result=val4+val5;
    case '-';
        result=val3-val5;
    case '*';
        
        result=val2*val5; 
    case '/';
        result=val1/val5;
    case '^';
        result=val6^val5;
        
end
set(handles.edit1,'String',num2str(result));

guidata(hObject,handles);

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



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


% --- Executes on button press in cebutton.
function cebutton_Callback(hObject, eventdata, handles)
% hObject    handle to cebutton (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 backspace.
function backspace_Callback(hObject, eventdata, handles)
% hObject    handle to backspace (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 Cbutton.
function Cbutton_Callback(hObject, eventdata, handles)
set(handles.edit1,'String','0');
% hObject    handle to Cbutton (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 + -