www.gusucode.com > MATLAB——水声速度计算源码程序 > MATLAB——水声速度计算源码程序/Calculator/Calculator.m

    function varargout = Calculator(varargin)
% CALCULATOR M-file for Calculator.fig
%      CALCULATOR, by itself, creates a new CALCULATOR or raises the existing
%      singleton*.
%
%      H = CALCULATOR returns the handle to a new CALCULATOR or the handle to
%      the existing singleton*.
%
%      CALCULATOR('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CALCULATOR.M with the given input arguments.
%
%      CALCULATOR('Property','Value',...) creates a new CALCULATOR or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Calculator_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Calculator_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 Calculator

% Last Modified by GUIDE v2.5 17-Dec-2008 17:12:53

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

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Calculator wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Calculator_OutputFcn(hObject, eventdata, handles) 
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global a
global e
global b
global c
global d
global f
global g
global h
global t
global S
global PP
global MP
global MS
global MMP
global MC
MMP='0.';
MC='0.';
S='0.';
PP='0.';
MP='0.';
MS='0.';
a='';
b='';
c='';
d='';
e='';
f='';
g='';
h='';
t=0;
multiply='';
plus='';
minus=''; 
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','0.')
% 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;



function edtxt_Callback(hObject, eventdata, handles)
% hObject    handle to edtxt (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 edtxt as text
%        str2double(get(hObject,'String')) returns contents of edtxt as a double


% --- Executes during object creation, after setting all properties.
function edtxt_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edtxt (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 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)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MP
global t
Backspace1=get(handles.edtxt,'string');
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
    beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
    beep;
elseif (~isempty(multiply) | ~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
elseif (strcmp(MP,'0.')~=1)
elseif strcmp(Backspace1,'0.')
elseif (t==1)
    back=char(Backspace1);
    l=length(Backspace1);
    Backspace=back(1:l-1);
    if strcmp(back(end),'.')
        back=char(Backspace1);
        l=length(Backspace1);
        Backspace=back(1:l-1);
        Backspace=strcat(Backspace(1:end-1),'.');
        if (strcmp(Backspace,'.'))
            set(handles.edtxt,'String','0.');
            t=0;
        elseif ((strcmp(Backspace(end-1),'-')))
            set(handles.edtxt,'String','0.');
            t=0;
        else
            set(handles.edtxt,'String',Backspace);

        end

    else
        set(handles.edtxt,'String',Backspace);
    end



else
    back=char(Backspace1);
    l=length(Backspace1);
    Backspace=back(1:l-2);
    if (isempty(Backspace))|(strcmp(Backspace,'-'))
        set(handles.edtxt,'String','0.');
    else
        Backspace=strcat(Backspace,'.');
        set(handles.edtxt,'String',Backspace);
    end

end




% --- Executes on button press in CE.
function CE_Callback(hObject, eventdata, handles)
% hObject    handle to CE (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.edtxt,'String','0.')


% --- Executes on button press in C.
function C_Callback(hObject, eventdata, handles)
% hObject    handle to C (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MS
global MC
global MP
global a
global e
global b
global c
global d
global f
global g
global h
global t
a='';
b='';
c='';
d='';
e='';
f='';
g='';
h='';
t=0;
MP='0.';
MC='0.';
MS='0.';
multiply='';
plus='';
minus=''; 
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','0.')



% --- Executes on button press in n1.
function n1_Callback(hObject, eventdata, handles)
% hObject    handle to n1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MS
global MC
global MP
global a
global e
global b
global c
global d
global f
global g
global h
global t
global x
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | strcmp(MS,'0.')~=1| strcmp(MC,'0.')~=0| strcmp(MP,'0.')~=1|~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
a=multiply;
b=plus;
c=minus;
d=equal;
e=divide;
f=kasr;
g=percent;
h=sqrtc;
x=MS;
MS='0.';
MP='0.';
MC='';
multiply='';
plus='';
minus=''; 
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','1.');
else
    n1=get(handles.edtxt,'string');
    if (strcmp(n1,'0.'))
        if (t==1)
            set(handles.edtxt,'String','0.1');
        else
            set(handles.edtxt,'String','1.');
        end
    else
        if (t==1)
            n1=strcat(n1,'1');
            set(handles.edtxt,'String',n1);
        else
            n1=strcat(n1(1:end-1),'1.');
            set(handles.edtxt,'String',n1);
        end
    end
end



% --- Executes on button press in n2.
function n2_Callback(hObject, eventdata, handles)
% hObject    handle to n2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MS
global MC
global MP
global a
global e
global b
global c
global d
global f
global g
global h
global t
global x
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | strcmp(MS,'0.')~=1 | strcmp(MC,'0.')~=0 | strcmp(MP,'0.')~=1 | ~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
a=multiply;
b=plus;
c=minus;
d=equal;
e=divide;
f=kasr;
g=percent;
h=sqrtc;
x=MS;
MS='0.';
MP='0.';
MC='';
multiply='';
plus='';
minus='';
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','2.');
else
    n2=get(handles.edtxt,'string');
    if (strcmp(n2,'0.'))
        if (t==1)
            set(handles.edtxt,'String','0.2');
        else
            set(handles.edtxt,'String','2.');
        end
    else
        if (t==1)
            n2=strcat(n2,'2');
            set(handles.edtxt,'String',n2);
        else
            n2=strcat(n2(1:end-1),'2.');
            set(handles.edtxt,'String',n2);
        end
    end  
 end   
    


% --- Executes on button press in n3.
function n3_Callback(hObject, eventdata, handles)
% hObject    handle to n3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MS
global MC
global MP
global a
global e
global b
global c
global d
global f
global g
global h
global t
global x
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | strcmp(MS,'0.')~=1 | strcmp(MC,'0.')~=0 | strcmp(MP,'0.')~=1 | ~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
a=multiply;
b=plus;
c=minus;
d=equal;
e=divide;
f=kasr;
g=percent;
h=sqrtc;
x=MS;
MS='0.';
MP='0.';
MC='';
multiply='';
plus='';
minus=''; 
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','3.');
else
 n3=get(handles.edtxt,'string');
    if (strcmp(n3,'0.'))
        if (t==1)
            set(handles.edtxt,'String','0.3');
        else
            set(handles.edtxt,'String','3.');
        end
    else
        if (t==1)
            n3=strcat(n3,'3');
            set(handles.edtxt,'String',n3);
        else
            n3=strcat(n3(1:end-1),'3.');
            set(handles.edtxt,'String',n3);
        end
    end     
end   
  
    
% --- Executes on button press in n4.
function n4_Callback(hObject, eventdata, handles)
% hObject    handle to n4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MS
global MC
global MP
global a
global e
global b
global c
global d
global f
global g
global h
global t
global x
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | strcmp(MS,'0.')~=1 | strcmp(MC,'0.')~=0 | strcmp(MP,'0.')~=1 | ~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
a=multiply;
b=plus;
c=minus;
d=equal;
e=divide;
f=kasr;
g=percent;
h=sqrtc;
x=MS;
MS='0.';
MP='0.';
MC='';
multiply='';
plus='';
minus=''; 
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','4.');
else
 n4=get(handles.edtxt,'string');
    if (strcmp(n4,'0.'))
        if (t==1)
            set(handles.edtxt,'String','0.4');
        else
            set(handles.edtxt,'String','4.');
        end
    else
        if (t==1)
            n4=strcat(n4,'4');
            set(handles.edtxt,'String',n4);
        else
            n4=strcat(n4(1:end-1),'4.');
            set(handles.edtxt,'String',n4);
        end
    end
end



% --- Executes on button press in n5.
function n5_Callback(hObject, eventdata, handles)
% hObject    handle to n5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MS
global MC
global MP
global a
global e
global b
global c
global d
global f
global g
global h
global t
global x
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | strcmp(MS,'0.')~=1 | strcmp(MC,'0.')~=0 | strcmp(MP,'0.')~=1 | ~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
a=multiply;
b=plus;
c=minus;
d=equal;
e=divide;
f=kasr;
g=percent;
h=sqrtc;
x=MS;
MS='0.';
MP='0.';
MC='';
multiply='';
plus='';
minus=''; 
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','5.');
else
  n5=get(handles.edtxt,'string');
    if (strcmp(n5,'0.'))
        if (t==1)
            set(handles.edtxt,'String','0.5');
        else
            set(handles.edtxt,'String','5.');
        end
    else
        if (t==1)
            n5=strcat(n5,'5');
            set(handles.edtxt,'String',n5);
        else
            n5=strcat(n5(1:end-1),'5.');
            set(handles.edtxt,'String',n5);
        end
    end  
end      
 


% --- Executes on button press in n6.
function n6_Callback(hObject, eventdata, handles)
% hObject    handle to n6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MS
global MC
global MP
global a
global e
global b
global c
global d
global f
global g
global h
global t
global x
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | strcmp(MS,'0.')~=1 | strcmp(MC,'0.')~=0 | strcmp(MP,'0.')~=1 | ~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
a=multiply;
b=plus;
c=minus;
d=equal;
e=divide;
f=kasr;
g=percent;
h=sqrtc;
x=MS;
MS='0.';
MP='0.';
MC='';
multiply='';
plus='';
minus=''; 
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','6.');
else
n6=get(handles.edtxt,'string');
    if (strcmp(n6,'0.'))
        if (t==1)
            set(handles.edtxt,'String','0.6');
        else
            set(handles.edtxt,'String','6.');
        end
    else
        if (t==1)
            n6=strcat(n6,'6');
            set(handles.edtxt,'String',n6);
        else
            n6=strcat(n6(1:end-1),'6.');
            set(handles.edtxt,'String',n6);
        end
    end  
end       
   


% --- Executes on button press in n7.
function n7_Callback(hObject, eventdata, handles)
% hObject    handle to n7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MS
global MC
global MP
global a
global e
global b
global c
global d
global f
global g
global h
global t
global x
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | strcmp(MS,'0.')~=1 | strcmp(MC,'0.')~=0 | strcmp(MP,'0.')~=1 | ~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
a=multiply;
b=plus;
c=minus;
d=equal;
e=divide;
f=kasr;
g=percent;
h=sqrtc;
x=MS;
MS='0.';
MP='0.';
MC='';
multiply='';
plus='';
minus=''; 
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','7.');
else
 n7=get(handles.edtxt,'string');
    if (strcmp(n7,'0.'))
        if (t==1)
            set(handles.edtxt,'String','0.7');
        else
            set(handles.edtxt,'String','7.');
        end
    else
        if (t==1)
            n7=strcat(n7,'7');
            set(handles.edtxt,'String',n7);
        else
            n7=strcat(n7(1:end-1),'7.');
            set(handles.edtxt,'String',n7);
        end
    end
end


% --- Executes on button press in n8.
function n8_Callback(hObject, eventdata, handles)
% hObject    handle to n8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MS
global MC
global MP
global a
global e
global b
global c
global d
global f
global g
global h
global t
global x
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | strcmp(MS,'0.')~=1 | strcmp(MC,'0.')~=0 | strcmp(MP,'0.')~=1 | ~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
a=multiply;
b=plus;
c=minus;
d=equal;
e=divide;
f=kasr;
g=percent;
h=sqrtc;
x=MS;
MS='0.';
MP='0.';
MC='';
multiply='';
plus='';
minus='';
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','8.');
else
 n8=get(handles.edtxt,'string');
    if (strcmp(n8,'0.'))
        if (t==1)
            set(handles.edtxt,'String','0.8');
        else
            set(handles.edtxt,'String','8.');
        end
    else
        if (t==1)
            n8=strcat(n8,'8');
            set(handles.edtxt,'String',n8);
        else
            n8=strcat(n8(1:end-1),'8.');
            set(handles.edtxt,'String',n8);
        end
    end  
end       
    

 
% --- Executes on button press in n9.
function n9_Callback(hObject, eventdata, handles)
% hObject    handle to n9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MS
global MC
global MP
global a
global e
global b
global c
global d
global f
global g
global h
global t
global x
global y
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | strcmp(MS,'0.')~=1 | strcmp(MC,'0.')~=0 | strcmp(MP,'0.')~=1 | ~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
a=multiply;
b=plus;
c=minus;
d=equal;
e=divide;
f=kasr;
g=percent;
h=sqrtc;
x=MS;
MS='0.';
MP='0.';
MC='';
multiply='';
plus='';
minus='';
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','9.');
else
 n9=get(handles.edtxt,'string');
    if (strcmp(n9,'0.'))
        if (t==1)
            set(handles.edtxt,'String','0.9');
        else
            set(handles.edtxt,'String','9.');
        end
    else
        if (t==1)
            n9=strcat(n9,'9');
            set(handles.edtxt,'String',n9);
        else
            n9=strcat(n9(1:end-1),'9.');
            set(handles.edtxt,'String',n9);
        end
    end  
end   


% --- Executes on button press in n0.
function n0_Callback(hObject, eventdata, handles)
% hObject    handle to n0 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MS
global MC
global MP
global a
global e
global b
global c
global d
global f
global g
global h
global t
global x
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | strcmp(MS,'0.')~=1 | strcmp(MC,'0.')~=0 | strcmp(MP,'0.')~=1 | ~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
a=multiply;
b=plus;
c=minus;
d=equal;
e=divide;
f=kasr;
g=percent;
h=sqrtc;
x=MS;
MS='0.';
MP='0.';
MC='';
multiply='';
plus='';
minus='' ;
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','0.');
else
    n0=get(handles.edtxt,'string');
    if (strcmp(n0,'0.'))
        if (t==1)
            set(handles.edtxt,'String','0.0');
        else
           
        end
    else
        if (t==1)
            n0=strcat(n0,'0');
            set(handles.edtxt,'String',n0);
        else
            n0=strcat(n0(1:end-1),'0.');
            set(handles.edtxt,'String',n0);
        end
    end  
end   
    
 

% --- Executes on button press in np.
function np_Callback(hObject, eventdata, handles)
% hObject    handle to np (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global a
global e
global b
global c
global d
global f
global g
global h
global t
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | ~isempty(plus) | ~isempty(minus) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
    a=multiply;
    b=plus;
    c=minus;
    d=equal;
    e=divide;
    f=kasr;
    g=percent;
    h=sqrtc;
    multiply='';
    plus='';
    minus='';
    equal='';
    divide='';
    sqrtc='';
    kasr='';
    percent='';
    set(handles.edtxt,'String','0.');
    np=get(handles.edtxt,'string');
    if (strcmp(np,'0.'))
        if t==1
            nnp=regexp(np,'[-]');
            if nnp>0
                set(handles.edtxt,'String',np(2:end));
            else
                np=strcat('-',np);
                set(handles.edtxt,'String',np);
            end
        end
    else
        nnp=regexp(np,'[-]');
        if nnp>0
            set(handles.edtxt,'String',np(2:end));
        else
            np=strcat('-',np);
            set(handles.edtxt,'String',np);
        end
    end
else
    np=get(handles.edtxt,'string');
    if (strcmp(np,'0.'))
       if t==1 
       nnp=regexp(np,'[-]');
        if nnp>0
            set(handles.edtxt,'String',np(2:end));
        else
            np=strcat('-',np);
            set(handles.edtxt,'String',np);
        end
       end
    else
        nnp=regexp(np,'[-]');
        if nnp>0
            set(handles.edtxt,'String',np(2:end));
        else
            np=strcat('-',np);
            set(handles.edtxt,'String',np);
        end
    end
end


% --- Executes on button press in dot.
function dot_Callback(hObject, eventdata, handles)
% hObject    handle to dot (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global MS
global MC
global MP
global a
global e
global b
global c
global d
global f
global g
global h
global t
global x
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | strcmp(MS,'0.')~=1 | strcmp(MC,'0.')~=0 | strcmp(MP,'0.')~=1 | ~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide)| ~isempty(kasr) | ~isempty(sqrtc) | ~isempty(percent))
a=multiply;
b=plus;
c=minus;
d=equal;
e=divide;
f=kasr;
g=percent;
h=sqrtc;
x=MS;
MS='0.';
MP='0.';
MC='';
multiply='';
plus='';
minus=''; 
equal=''; 
divide='';
sqrtc='';
kasr='';
percent='';
set(handles.edtxt,'String','0.');
t=get(handles.dot,'value');
else
t=get(handles.dot,'value');
end


% --- Executes on button press in divide.
function divide_Callback(hObject, eventdata, handles)
% hObject    handle to divide (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global a
global e
global b
global c
global t
t=0;
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
       
elseif (isempty(multiply)& isempty(plus) & isempty(minus)& isempty(equal)& isempty(kasr) & isempty(sqrtc)& isempty(percent))
    divide=str2double(get(handles.edtxt,'string'));
    ansd=e/divide;
    if (~isempty(e) & isnan(ansd))
        set(handles.edtxt,'string','Result of function is undefined.')
    
    elseif (~isempty(e) & abs(ansd)==inf)
        set(handles.edtxt,'string','Cannot divide by zero.')

    elseif ~isempty(e);
        ansd=e/divide;
        if (fix(ansd)-ansd==0)
            set(handles.edtxt,'string',ansd);
            ansd=get(handles.edtxt,'string');
            ansd=strcat(ansd,'.');
            set(handles.edtxt,'string',ansd);
            divide=str2double(ansd(1:end-1));
            e='';
        else
            set(handles.edtxt,'string',ansd);
            divide=ansd;
            e='';
        end
    end
    %%%%%%%%%%%%%%%
    if ~isempty(a);
        ansm=a*divide;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            divide=str2double(ansm(1:end-1));
            a='';
        else
            set(handles.edtxt,'string',ansm);
            divide=ansm;
            a='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(c);
        ansu=c-divide;
        if (fix(ansu)-ansu==0)
            set(handles.edtxt,'string',ansu);
            ansu=get(handles.edtxt,'string');
            ansu=strcat(ansu,'.');
            set(handles.edtxt,'string',ansu);
            divide=str2double(ansu(1:end-1));
            c='';
        else
            set(handles.edtxt,'string',ansu);
            divide=ansu;
            c='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(b);
        ansp=b+divide;
        if (fix(ansp)-ansp==0)
            set(handles.edtxt,'string',ansp);
            ansp=get(handles.edtxt,'string');
            ansp=strcat(ansp,'.');
            set(handles.edtxt,'string',ansp);
            divide=str2double(ansp(1:end-1));
            b='';
        else
            set(handles.edtxt,'string',ansp);
            divide=ansp;
            b='';
        end
    end
else
    multiply='';
    plus='';
    minus='';
    equal='';
    sqrtc='';
    percent='';
    kasr='';
    b='';
    a='';
    e='';
    c='';
divide=str2double(get(handles.edtxt,'string'));
 ansd=e/divide;
 if (~isempty(e) & isnan(ansd))
     set(handles.edtxt,'string','Result of function is undefined.')
 elseif (~isempty(e) & abs(ansd)==inf)
     set(handles.edtxt,'string','Cannot divide by zero.')
 elseif ~isempty(e);
     ansd=e/divide;
     if (fix(ansd)-ansd==0)
         set(handles.edtxt,'string',ansd);
         ansd=get(handles.edtxt,'string');
         ansd=strcat(ansd,'.');
         set(handles.edtxt,'string',ansd);
         divide=str2double(ansd(1:end-1));
         e='';
     else
         set(handles.edtxt,'string',ansd);
         divide=ansd;
         e='';
     end
 end
 %%%%%%%%%%%%%%%
    if ~isempty(a);
        ansm=a*divide;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            divide=str2double(ansm(1:end-1));
            a='';
        else
            set(handles.edtxt,'string',ansm);
            divide=ansm;
            a='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(c);
        ansu=c-divide;
        if (fix(ansu)-ansu==0)
            set(handles.edtxt,'string',ansu);
            ansu=get(handles.edtxt,'string');
            ansu=strcat(ansu,'.');
            set(handles.edtxt,'string',ansu);
            divide=str2double(ansu(1:end-1));
            c='';
        else
            set(handles.edtxt,'string',ansu);
            divide=ansu;
            c='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(b);
        ansp=b+divide;
        if (fix(ansp)-ansp==0)
            set(handles.edtxt,'string',ansp);
            ansp=get(handles.edtxt,'string');
            ansp=strcat(ansp,'.');
            set(handles.edtxt,'string',ansp);
            divide=str2double(ansp(1:end-1));
            b='';
        else
            set(handles.edtxt,'string',ansp);
            divide=ansp;
            b='';
        end
    end
end



% --- Executes on button press in sqrt.
function sqrt_Callback(hObject, eventdata, handles)
% hObject    handle to sqrt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
divide='';
plus='';
minus='';
equal='';
multiply='';
percent='';
sqrtc=get(handles.edtxt,'string');
if (strcmp(sqrtc,'Cannot divide by zero.'))
    set(handles.edtxt,'string','Cannot divide by zero.');
    beep;
elseif (str2double(get(handles.edtxt,'string'))<0 | strcmp(sqrtc,'Invalid input for function.'))
    set(handles.edtxt,'string','Invalid input for function.');
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (isempty(divide)& isempty(plus) & isempty(minus)& isempty(equal)& isempty(kasr) & isempty(multiply)& isempty(percent))
    sqrtc=str2double(get(handles.edtxt,'string'));
    sqrtc=sqrt(sqrtc);
    if (fix(sqrtc)-sqrtc==0)
        set(handles.edtxt,'String',sqrtc);
        sqrtc=get(handles.edtxt,'string');
        sqrtc=strcat(sqrtc,'.');
        set(handles.edtxt,'String',sqrtc);
 
    else
      
           set(handles.edtxt,'string',sqrtc);
       
    end
else
    divide='';
    plus='';
    minus='';
    equal='';
    multiply='';
    percent='';
    kasr='';
    sqrtc=str2double(get(handles.edtxt,'string'));
    sqrtc=sqrt(sqrtc);
     if (fix(sqrtc)-sqrtc==0)
        set(handles.edtxt,'String',sqrtc);
        sqrtc=get(handles.edtxt,'string');
        sqrtc=strcat(sqrtc,'.');
        set(handles.edtxt,'String',sqrtc);

    else
        set(handles.edtxt,'string',sqrtc);

    end
       
end



% --- Executes on button press in multiply.
function multiply_Callback(hObject, eventdata, handles)
% hObject    handle to multiply (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global a
global e
global b
global c
global t
t=0;
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))

elseif (isempty(divide)& isempty(plus) & isempty(minus)& isempty(equal)& isempty(kasr) & isempty(sqrtc)& isempty(percent))
multiply=str2double(get(handles.edtxt,'string'));
   ansd=e/multiply;  
   if (~isempty(e) & isnan(ansd))
       set(handles.edtxt,'string','Result of function is undefined.')

   elseif (~isempty(e) & abs(ansd)==inf)
       set(handles.edtxt,'string','Cannot divide by zero.')

   elseif ~isempty(e);
       ansd=e/multiply;
       if (fix(ansd)-ansd==0)
           set(handles.edtxt,'string',ansd);
           ansd=get(handles.edtxt,'string');
           ansd=strcat(ansd,'.');
           set(handles.edtxt,'string',ansd);
           multiply=str2double(ansd(1:end-1));
           e='';
       else
           set(handles.edtxt,'string',ansd);
            multiply=ansd;
            e='';
        end
    end
    %%%%%%%%%%%%%%%
    if ~isempty(a);
        ansm=a*multiply;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            multiply=str2double(ansm(1:end-1));
            a='';
        else
            set(handles.edtxt,'string',ansm);
            multiply=ansm;
            a='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(c);
        ansu=c-multiply;
        if (fix(ansu)-ansu==0)
            set(handles.edtxt,'string',ansu);
            ansu=get(handles.edtxt,'string');
            ansu=strcat(ansu,'.');
            set(handles.edtxt,'string',ansu);
            multiply=str2double(ansu(1:end-1));
            c='';
        else
            set(handles.edtxt,'string',ansu);
            multiply=ansu;
            c='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(b);
        ansp=b+multiply;
        if (fix(ansp)-ansp==0)
            set(handles.edtxt,'string',ansp);
            ansp=get(handles.edtxt,'string');
            ansp=strcat(ansp,'.');
            set(handles.edtxt,'string',ansp);
            multiply=str2double(ansp(1:end-1));
            b='';
        else
            set(handles.edtxt,'string',ansp);
            multiply=ansp;
            b='';
        end
    end
else
    divide='';
    plus='';
    minus='';
    equal='';
    sqrtc='';
    percent='';
    kasr='';
    b='';
    a='';
    e='';
    c='';
multiply=str2double(get(handles.edtxt,'string'));
    ansd=e/multiply;
    if (~isempty(e) & isnan(ansd))
        set(handles.edtxt,'string','Result of function is undefined.')

    elseif (~isempty(e) & abs(ansd)==inf)
        set(handles.edtxt,'string','Cannot divide by zero.')

    elseif ~isempty(e);
        ansd=e/multiply;
        if (fix(ansd)-ansd==0)
            set(handles.edtxt,'string',ansd);
            ansd=get(handles.edtxt,'string');
            ansd=strcat(ansd,'.');
            set(handles.edtxt,'string',ansd);
            multiply=str2double(ansd(1:end-1));
            e='';
        else
            set(handles.edtxt,'string',ansd);
            multiply=ansd;
            e='';
        end
    end
    %%%%%%%%%%%%%%%
    if ~isempty(a);
        ansm=a*multiply;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            multiply=str2double(ansm(1:end-1));
            a='';
        else
            set(handles.edtxt,'string',ansm);
            multiply=ansm;
            a='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(c);
        ansu=c-multiply;
        if (fix(ansu)-ansu==0)
            set(handles.edtxt,'string',ansu);
            ansu=get(handles.edtxt,'string');
            ansu=strcat(ansu,'.');
            set(handles.edtxt,'string',ansu);
            multiply=str2double(ansu(1:end-1));
            c='';
        else
            set(handles.edtxt,'string',ansu);
            multiply=ansu;
            c='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(b);
        ansp=b+multiply;
        if (fix(ansp)-ansp==0)
            set(handles.edtxt,'string',ansp);
            ansp=get(handles.edtxt,'string');
            ansp=strcat(ansp,'.');
            set(handles.edtxt,'string',ansp);
            multiply=str2double(ansp(1:end-1));
            b='';
        else
            set(handles.edtxt,'string',ansp);
            multiply=ansp;
            b='';
        end
    end
end



% --- Executes on button press in percent.
function percent_Callback(hObject, eventdata, handles)
% hObject    handle to percent (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global a
global b
global c
global d
global e
global g
global t
t=0;
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (isempty(multiply) & isempty(plus) & isempty(minus) & isempty(equal)& isempty(sqrtc) & isempty(kasr)& isempty(divide))
percent=str2double(get(handles.edtxt,'string'));
else
multiply='';
plus='';
minus=''; 
equal='';
divide='';
sqrtc='';
kasr='';
percent=str2double(get(handles.edtxt,'string'));
end
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (~isempty(multiply) | ~isempty(plus) | ~isempty(minus) | ~isempty(equal) | ~isempty(divide))
a=multiply;
b=plus;
c=minus;
d=equal;
e=divide;
multiply='';
plus='';
minus='';
equal=''; 
divide='';
else
   set(handles.edtxt,'string','0.');
    if (isempty(percent)& ~isempty(e))
        percent=str2double(get(handles.edtxt,'string'));
                     ansd=e*percent/100;
            if (fix(ansd)-ansd==0)
                set(handles.edtxt,'string',ansd);
                ansd=get(handles.edtxt,'string');
                ansd=strcat(ansd,'.');
                set(handles.edtxt,'string',ansd);
                ansd=str2double(ansd(1:end-1));
               percent=ansd;
            else
                set(handles.edtxt,'string',ansd);
               
            end
       
    elseif(~isempty(percent)& ~isempty(e))
         ansd=e*percent/100;
        if (fix(ansd)-ansd==0)
            set(handles.edtxt,'string',ansd);
            ansd=get(handles.edtxt,'string');
            ansd=strcat(ansd,'.');
            set(handles.edtxt,'string',ansd);
            ansd=str2double(ansd(1:end-1));
            percent=ansd;
        else
            set(handles.edtxt,'string',ansd);
            
        end

    end
    %%%%%%%%%%%%%%%
    if (isempty(percent) & ~isempty(a))
        percent=str2double(get(handles.edtxt,'string'));
        ansm=a*percent/100;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            ansm=str2double(ansm(1:end-1));

        else
            set(handles.edtxt,'string',ansm);

        end

    elseif(~isempty(percent) & ~isempty(a))
        ansm=a*percent/100;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            ansm=str2double(ansm(1:end-1));

        else
            set(handles.edtxt,'string',ansm);

        end

    end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if (isempty(percent) & ~isempty(c))
        percent=str2double(get(handles.edtxt,'string'));
                    ansu=c*percent/100;
            if (fix(ansu)-ansu==0)
                set(handles.edtxt,'string',ansu);
                ansu=get(handles.edtxt,'string');
                ansu=strcat(ansu,'.');
                set(handles.edtxt,'string',ansu);
                ansu=str2double(ansu(1:end-1));
               
            else
                set(handles.edtxt,'string',ansu);
               
            end
           elseif(~isempty(percent) & ~isempty(c))
        ansu=c*percent/100;
        if (fix(ansu)-ansu==0)
            set(handles.edtxt,'string',ansu);
            ansu=get(handles.edtxt,'string');
            ansu=strcat(ansu,'.');
            set(handles.edtxt,'string',ansu);
            ansu=str2double(ansu(1:end-1));
            
        else
            set(handles.edtxt,'string',ansu);
            
        end

    end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (isempty(percent) & ~isempty(b))
    percent=str2double(get(handles.edtxt,'string'));
      ansp=b*percent/100;
    if (fix(ansp)-ansp==0)
        set(handles.edtxt,'string',ansp);
        ansp=get(handles.edtxt,'string');
        ansp=strcat(ansp,'.');
        set(handles.edtxt,'string',ansp);
        ansp=str2double(ansp(1:end-1));

    else

        set(handles.edtxt,'string',ansp);
    end
elseif(~isempty(percent) & ~isempty(b))

    ansp=b*percent/100;
    if (fix(ansp)-ansp==0)
        set(handles.edtxt,'string',ansp);
        ansp=get(handles.edtxt,'string');
        ansp=strcat(ansp,'.');
        set(handles.edtxt,'string',ansp);
        ansp=str2double(ansp(1:end-1));

    else


        set(handles.edtxt,'string',ansp);

    end

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (isempty(percent) & ~isempty(g))
        percent=str2double(get(handles.edtxt,'string'));
        ansm=g*percent/100;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            ansm=str2double(ansm(1:end-1));

        else
            set(handles.edtxt,'string',ansm);

        end

    elseif(~isempty(percent) & ~isempty(g))
        ansm=g*percent/100;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            ansm=str2double(ansm(1:end-1));

        else
            set(handles.edtxt,'string',ansm);

        end

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
end



% --- Executes on button press in minus.
function minus_Callback(hObject, eventdata, handles)
% hObject    handle to minus (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global a
global e
global b
global c
global t
t=0;
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif (isempty(multiply)& isempty(divide) & isempty(kasr)& isempty(equal)& isempty(plus) & isempty(sqrtc)& isempty(percent))
minus=str2double(get(handles.edtxt,'string'));
    ansd=e/minus;
    if (~isempty(e) & isnan(ansd))
        set(handles.edtxt,'string','Result of function is undefined.')

    elseif (~isempty(e) & abs(ansd)==inf)
        set(handles.edtxt,'string','Cannot divide by zero.')
    elseif ~isempty(e);
        ansd=e/minus;
        if (fix(ansd)-ansd==0)
            set(handles.edtxt,'string',ansd);
            ansd=get(handles.edtxt,'string');
            ansd=strcat(ansd,'.');
            set(handles.edtxt,'string',ansd);
            minus=str2double(ansd(1:end-1));
            e='';
        else
            set(handles.edtxt,'string',ansd);
            minus=ansd;
            e='';
        end
    end
    %%%%%%%%%%%%%%%
    if ~isempty(a);
        ansm=a*minus;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            minus=str2double(ansm(1:end-1));
            a='';
        else
            set(handles.edtxt,'string',ansm);
            minus=ansm;
            a='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(c);
        ansu=c-minus;
        if (fix(ansu)-ansu==0)
            set(handles.edtxt,'string',ansu);
            ansu=get(handles.edtxt,'string');
            ansu=strcat(ansu,'.');
            set(handles.edtxt,'string',ansu);
            minus=str2double(ansu(1:end-1));
            c='';
        else
            set(handles.edtxt,'string',ansu);
            minus=ansu;
            c='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(b);
        ansp=b+minus;
        if (fix(ansp)-ansp==0)
            set(handles.edtxt,'string',ansp);
            ansp=get(handles.edtxt,'string');
            ansp=strcat(ansp,'.');
            set(handles.edtxt,'string',ansp);
            minus=str2double(ansp(1:end-1));
            b='';
        else
            set(handles.edtxt,'string',ansp);
            minus=ansp;
            b='';
        end
    end
else
    multiply='';
    plus='';
    divide='' ;
    equal='';
    sqrtc='';
    percent='';
    kasr='';
    b='';
    a='';
    e='';
    c='';
    minus=str2double(get(handles.edtxt,'string'));
    
    ansd=e/minus;
    
    if (~isempty(e) & isnan(ansd))
        set(handles.edtxt,'string','Result of function is undefined.')
    
    elseif (~isempty(e) & abs(ansd)==inf)
        set(handles.edtxt,'string','Cannot divide by zero.')

    elseif ~isempty(e);
        ansd=e/minus;
        if (fix(ansd)-ansd==0)
            set(handles.edtxt,'string',ansd);
            ansd=get(handles.edtxt,'string');
            ansd=strcat(ansd,'.');
            set(handles.edtxt,'string',ansd);
            minus=str2double(ansd(1:end-1));
            e='';
        else
            set(handles.edtxt,'string',ansd);
            minus=ansd;
            e='';
        end
    end
    %%%%%%%%%%%%%%%
    if ~isempty(a);
        ansm=a*minus;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            minus=str2double(ansm(1:end-1));
            a='';
        else
            set(handles.edtxt,'string',ansm);
            minus=ansm;
            a='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(c);
        ansu=c-minus;
        if (fix(ansu)-ansu==0)
            set(handles.edtxt,'string',ansu);
            ansu=get(handles.edtxt,'string');
            ansu=strcat(ansu,'.');
            set(handles.edtxt,'string',ansu);
            minus=str2double(ansu(1:end-1));
            c='';
        else
            set(handles.edtxt,'string',ansu);
            minus=ansu;
            c='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(b);
        ansp=b+minus;
        if (fix(ansp)-ansp==0)
            set(handles.edtxt,'string',ansp);
            ansp=get(handles.edtxt,'string');
            ansp=strcat(ansp,'.');
            set(handles.edtxt,'string',ansp);
            minus=str2double(ansp(1:end-1));
            b='';
        else
            set(handles.edtxt,'string',ansp);
            minus=ansp;
            b='';
        end
    end
end



% --- Executes on button press in kasr.
function kasr_Callback(hObject, eventdata, handles)
% hObject    handle to kasr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
kasr=get(handles.edtxt,'string');
if (strcmp(kasr,'Invalid input for function.'))
    set(handles.edtxt,'string','Invalid input for function.');
    beep;
elseif ( str2double(get(handles.edtxt,'string'))==0 | strcmp(kasr,'Cannot divide by zero.'))
    set(handles.edtxt,'string','Cannot divide by zero.');
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;    
elseif (isempty(multiply)& isempty(divide) & isempty(minus)& isempty(equal)& isempty(plus) & isempty(sqrtc)& isempty(percent))
    kasr=str2double(get(handles.edtxt,'string'));
    kasr=1/kasr;
    if (fix(kasr)-kasr==0)
        set(handles.edtxt,'string',kasr);
        kasr=get(handles.edtxt,'string');
        kasr=strcat(kasr,'.');
        set(handles.edtxt,'string',kasr);
    else
        set(handles.edtxt,'string',kasr);
    end
else
    multiply='';
    divide='';
    minus='';
    equal='';
    sqrtc='';
    percent='';
    plus='';
    kasr=str2double(get(handles.edtxt,'string'));
    kasr=1/kasr;
    if (fix(kasr)-kasr==0)
        set(handles.edtxt,'string',kasr);
        kasr=get(handles.edtxt,'string');
        kasr=strcat(kasr,'.');
        set(handles.edtxt,'string',kasr);
    else
        set(handles.edtxt,'string',kasr);
    end
end

 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



% --- Executes on button press in plus.
function plus_Callback(hObject, eventdata, handles)
% hObject    handle to plus (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global a
global e
global b
global c
global t
t=0;
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))

elseif (isempty(multiply)& isempty(divide) & isempty(minus)& isempty(equal)& isempty(kasr) & isempty(sqrtc)& isempty(percent))
    plus=str2double(get(handles.edtxt,'string'));
        ansd=e/plus;
    if (~isempty(e) & isnan(ansd))
        set(handles.edtxt,'string','Result of function is undefined.')

    elseif (~isempty(e) & abs(ansd)==inf)
        set(handles.edtxt,'string','Cannot divide by zero.')


    elseif ~isempty(e);
        ansd=e/plus;
        if (fix(ansd)-ansd==0)
            set(handles.edtxt,'string',ansd);
            ansd=get(handles.edtxt,'string');
            ansd=strcat(ansd,'.');
            set(handles.edtxt,'string',ansd);
            plus=str2double(ansd(1:end-1));
            e='';
        else
            set(handles.edtxt,'string',ansd);
            plus=ansd;
            e='';
        end
    end

    %%%%%%%%%%%%%%%
    if ~isempty(a);
        ansm=a*plus;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            plus=str2double(ansm(1:end-1));
            a='';
        else
            set(handles.edtxt,'string',ansm);
            plus=ansm;
            a='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(c);
        ansu=c-plus;
        if (fix(ansu)-ansu==0)
            set(handles.edtxt,'string',ansu);
            ansu=get(handles.edtxt,'string');
            ansu=strcat(ansu,'.');
            set(handles.edtxt,'string',ansu);
            plus=str2double(ansu(1:end-1));
            c='';
        else
            set(handles.edtxt,'string',ansu);
            plus=ansu;
            c='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(b);
        ansp=b+plus;
        if (fix(ansp)-ansp==0)
            set(handles.edtxt,'string',ansp);
            ansp=get(handles.edtxt,'string');
            ansp=strcat(ansp,'.');
            set(handles.edtxt,'string',ansp);
            plus=str2double(ansp(1:end-1));
            b='';
        else
            set(handles.edtxt,'string',ansp);
            plus=ansp;
            b='';
        end
    end
else
    multiply='';
    divide='';
    minus='';
    equal='';
    sqrtc='';
    percent='';
    kasr='';
    b='';
    a='';
    e='';
    c='';
    plus=str2double(get(handles.edtxt,'string'));
    ansd=e/plus;
    if (~isempty(e) & isnan(ansd))
        set(handles.edtxt,'string','Result of function is undefined.')
    
    elseif (~isempty(e) & abs(ansd)==inf)
        set(handles.edtxt,'string','Cannot divide by zero.')
    
    elseif ~isempty(e);
        ansd=e/plus;
        if (fix(ansd)-ansd==0)
            set(handles.edtxt,'string',ansd);
            ansd=get(handles.edtxt,'string');
            ansd=strcat(ansd,'.');
            set(handles.edtxt,'string',ansd);
             plus=str2double(ansd(1:end-1));
            e='';
        else
            set(handles.edtxt,'string',ansd);
            plus=ansd;
            e='';
        end
    end
    %%%%%%%%%%%%%%%
    if ~isempty(a);
        ansm=a*plus;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            plus=str2double(ansm(1:end-1));
            a='';
        else
            set(handles.edtxt,'string',ansm);
            plus=ansm;
            a='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(c);
        ansu=c-plus;
        if (fix(ansu)-ansu==0)
            set(handles.edtxt,'string',ansu);
            ansu=get(handles.edtxt,'string');
            ansu=strcat(ansu,'.');
            set(handles.edtxt,'string',ansu);
             plus=str2double(ansu(1:end-1));
            c='';
        else
            set(handles.edtxt,'string',ansu);
            plus=ansu;
            c='';
        end
    end
    %%%%%%%%%%%%%%%%%
    if ~isempty(b);
        ansp=b+plus;
        if (fix(ansp)-ansp==0)
            set(handles.edtxt,'string',ansp);
            ansp=get(handles.edtxt,'string');
            ansp=strcat(ansp,'.');
            set(handles.edtxt,'string',ansp);
            plus=str2double(ansp(1:end-1));
            b='';
        else
            set(handles.edtxt,'string',ansp);
            plus=ansp;
            b='';
        end
    end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% --- Executes on button press in equal.
function equal_Callback(hObject, eventdata, handles)
% hObject    handle to equal (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global kasr
global sqrtc
global percent
global multiply
global divide
global plus
global minus
global equal
global a
global e
global b
global c
global t
t=0;
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))

elseif (isempty(multiply)& isempty(divide) & isempty(minus)& isempty(plus)& isempty(kasr) & isempty(sqrtc)& isempty(percent))
    if (isempty(equal)& ~isempty(e))
        equal=str2double(get(handles.edtxt,'string'));
        %if ~isempty(e);
         ansd=e/equal;
         if (isnan(ansd))
             set(handles.edtxt,'string','Result of function is undefined.')

         elseif (abs(ansd)==inf)
             set(handles.edtxt,'string','Cannot divide by zero.')

         elseif (fix(ansd)-ansd==0)
             set(handles.edtxt,'string',ansd);
             ansd=get(handles.edtxt,'string');
             ansd=strcat(ansd,'.');
             set(handles.edtxt,'string',ansd);
             ansd=str2double(ansd(1:end-1));
             e=ansd;
         else
            set(handles.edtxt,'string',ansd);
            e=ansd;
        end
        %end
    elseif(~isempty(equal)& ~isempty(e))
        ansd=e/equal;
        if (fix(ansd)-ansd==0)
            set(handles.edtxt,'string',ansd);
            ansd=get(handles.edtxt,'string');
            ansd=strcat(ansd,'.');
            set(handles.edtxt,'string',ansd);
            ansd=str2double(ansd(1:end-1));
            e=ansd;
        else
            set(handles.edtxt,'string',ansd);
            e=ansd;
        end

    end
    %%%%%%%%%%%%%%%
    if (isempty(equal) & ~isempty(a))
        equal=str2double(get(handles.edtxt,'string'));
        %if ~isempty(a);
            ansm=a*equal;
            if (fix(ansm)-ansm==0)
                set(handles.edtxt,'string',ansm);
                ansm=get(handles.edtxt,'string');
                ansm=strcat(ansm,'.');
                set(handles.edtxt,'string',ansm);
                ansm=str2double(ansm(1:end-1));
                a=ansm;
            else
                set(handles.edtxt,'string',ansm);
                a=ansm;
            end
        %end
    elseif(~isempty(equal) & ~isempty(a))
        ansm=a*equal;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            ansm=str2double(ansm(1:end-1));
            a=ansm;
        else
            set(handles.edtxt,'string',ansm);
            a=ansm;
        end

    end
%    
% %     if ~isempty(a);
% %         ansm=a*equal;
% %         if (fix(ansm)-ansm==0)
% %             set(handles.edtxt,'string',ansm);
% %             ansm=get(handles.edtxt,'string');
% %             ansm=strcat(ansm,'.');
% %             set(handles.edtxt,'string',ansm);
% %             equal=str2double(ansm(1:end-1));
% %             a='';
% %         else
% %             set(handles.edtxt,'string',ansm);
% %             ansm='';
% %             a='';
% %         end
% %     end
%     %%%%%%%%%%%%%%%%%
    if (isempty(equal) & ~isempty(c))
        equal=str2double(get(handles.edtxt,'string'));
        %if ~isempty(c);
            ansu=c-equal;
            if (fix(ansu)-ansu==0)
                set(handles.edtxt,'string',ansu);
                ansu=get(handles.edtxt,'string');
                ansu=strcat(ansu,'.');
                set(handles.edtxt,'string',ansu);
                ansu=str2double(ansu(1:end-1));
                c=ansu;
            else
                set(handles.edtxt,'string',ansu);
                c=ansu;
            end
       % end
    elseif(~isempty(equal) & ~isempty(c))
        ansu=c-equal;
        if (fix(ansu)-ansu==0)
            set(handles.edtxt,'string',ansu);
            ansu=get(handles.edtxt,'string');
            ansu=strcat(ansu,'.');
            set(handles.edtxt,'string',ansu);
            ansu=str2double(ansu(1:end-1));
            c=ansu;
        else
            set(handles.edtxt,'string',ansu);
            c=ansu;
        end

    end
%    
% %     if ~isempty(c);
% %         ansu=c-equal;
% %         if (fix(ansu)-ansu==0)
% %             set(handles.edtxt,'string',ansu);
% %             ansu=get(handles.edtxt,'string');
% %             ansu=strcat(ansu,'.');
% %             set(handles.edtxt,'string',ansu);
% %             equal=str2double(ansu(1:end-1));
% %             c='';
% %         else
% %             set(handles.edtxt,'string',ansu);
% %             ansu='';
% %             c='';
% %         end
% %     end
%     %%%%%%%%%%%%%%%%%
%             
    if (isempty(equal) & ~isempty(b))
        equal=str2double(get(handles.edtxt,'string'));
        %if ~isempty(b);
            ansp=b+equal;
            if (fix(ansp)-ansp==0)
                set(handles.edtxt,'string',ansp);
                ansp=get(handles.edtxt,'string');
                ansp=strcat(ansp,'.');
                set(handles.edtxt,'string',ansp);
                ansp=str2double(ansp(1:end-1));
                b=ansp;
            else
                set(handles.edtxt,'string',ansp);
                b=ansp;
            end
        %end
    elseif(~isempty(equal) & ~isempty(b))
        ansp=b+equal;
        if (fix(ansp)-ansp==0)
            set(handles.edtxt,'string',ansp);
            ansp=get(handles.edtxt,'string');
            ansp=strcat(ansp,'.');
            set(handles.edtxt,'string',ansp);
            ansp=str2double(ansp(1:end-1));
            b=ansp;
        else
            set(handles.edtxt,'string',ansp);
            b=ansp;
        end

    end
 
%     if ~isempty(b);
%         ansp=b+equal;
%         if (fix(ansp)-ansp==0)
%             set(handles.edtxt,'string',ansp);
%             ansp=get(handles.edtxt,'string');
%             ansp=strcat(ansp,'.');
%             set(handles.edtxt,'string',ansp);
%             equal=str2double(ansp(1:end-1));
%             b='';
%         else
%             set(handles.edtxt,'string',ansp);
%             ansp='';
%             b='';
%         end
%     end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

else
    multiply='';
    divide='';
    minus='';
    plus='';
    sqrtc='';
    percent='';
    kasr='';
%         b='';
%         a='';
%         e='';
%         c='';
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
    if (isempty(equal)& ~isempty(e))
        equal=str2double(get(handles.edtxt,'string'));
        
        ansd=e/equal;
        if (isnan(ansd))
            set(handles.edtxt,'string','Result of function is undefined.')

        elseif (abs(ansd)==inf)
            set(handles.edtxt,'string','Cannot divide by zero.')

        elseif (fix(ansd)-ansd==0)
            set(handles.edtxt,'string',ansd);
            ansd=get(handles.edtxt,'string');
            ansd=strcat(ansd,'.');
            set(handles.edtxt,'string',ansd);
            ansd=str2double(ansd(1:end-1));
            e=ansd;
        else
            set(handles.edtxt,'string',ansd);
            e=ansd;
        end
       
    elseif(~isempty(equal)& ~isempty(e))
        ansd=e/equal;
        if (fix(ansd)-ansd==0)
            set(handles.edtxt,'string',ansd);
            ansd=get(handles.edtxt,'string');
            ansd=strcat(ansd,'.');
            set(handles.edtxt,'string',ansd);
            ansd=str2double(ansd(1:end-1));
            e=ansd;
        else
            set(handles.edtxt,'string',ansd);
            e=ansd;
        end

    end
    %%%%%%%%%%%%%%%
    if (isempty(equal) & ~isempty(a))
        equal=str2double(get(handles.edtxt,'string'));
        
        ansm=a*equal;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            ansm=str2double(ansm(1:end-1));
            a=ansm;
        else
            set(handles.edtxt,'string',ansm);
            a=ansm;
        end
        
    elseif(~isempty(equal) & ~isempty(a))
        ansm=a*equal;
        if (fix(ansm)-ansm==0)
            set(handles.edtxt,'string',ansm);
            ansm=get(handles.edtxt,'string');
            ansm=strcat(ansm,'.');
            set(handles.edtxt,'string',ansm);
            ansm=str2double(ansm(1:end-1));
            a=ansm;
        else
            set(handles.edtxt,'string',ansm);
            a=ansm;
        end

    end
    %%%%%%%%%%%%%%%%%
    if (isempty(equal) & ~isempty(c))
        equal=str2double(get(handles.edtxt,'string'));
        
        ansu=c-equal;
        if (fix(ansu)-ansu==0)
            set(handles.edtxt,'string',ansu);
            ansu=get(handles.edtxt,'string');
            ansu=strcat(ansu,'.');
            set(handles.edtxt,'string',ansu);
            ansu=str2double(ansu(1:end-1));
            c=ansu;
        else
            set(handles.edtxt,'string',ansu);
            c=ansu;
        end
       
    elseif(~isempty(equal) & ~isempty(c))
        ansu=c-equal;
        if (fix(ansu)-ansu==0)
            set(handles.edtxt,'string',ansu);
            ansu=get(handles.edtxt,'string');
            ansu=strcat(ansu,'.');
            set(handles.edtxt,'string',ansu);
            ansu=str2double(ansu(1:end-1));
            c=ansu;
        else
            set(handles.edtxt,'string',ansu);
            c=ansu;
        end

    end
    %%%%%%%%%%%%%%%%%
    if (isempty(equal) & ~isempty(b))
        equal=str2double(get(handles.edtxt,'string'));
        
        ansp=b+equal;
        if (fix(ansp)-ansp==0)
            set(handles.edtxt,'string',ansp);
            ansp=get(handles.edtxt,'string');
            ansp=strcat(ansp,'.');
            set(handles.edtxt,'string',ansp);
            ansp=str2double(ansp(1:end-1));
            b=ansp;
        else
            set(handles.edtxt,'string',ansp);
            b=ansp;
        end
        
    elseif(~isempty(equal) & ~isempty(b))
        ansp=b+equal;
        if (fix(ansp)-ansp==0)
            set(handles.edtxt,'string',ansp);
            ansp=get(handles.edtxt,'string');
            ansp=strcat(ansp,'.');
            set(handles.edtxt,'string',ansp);
            ansp=str2double(ansp(1:end-1));
            b=ansp;
        else
            set(handles.edtxt,'string',ansp);
            b=ansp;
        end

    end

end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



% --------------------------------------------------------------------
function Exit_Callback(hObject, eventdata, handles)
% hObject    handle to Exit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
clc
question='    Do you want to exit?  ';
button=questdlg(question,'Exit','Yes','No','No');
switch(button)
    case 'Yes'
    close Calculator
end


% --------------------------------------------------------------------
function About_Callback(hObject, eventdata, handles)
% hObject    handle to About (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
open HELP.htm
% --------------------------------------------------------------------
function File_Callback(hObject, eventdata, handles)
% hObject    handle to File (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Help_Callback(hObject, eventdata, handles)
% hObject    handle to Help (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 MC.
function MC_Callback(hObject, eventdata, handles)
% hObject    handle to MC (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global MS
global S
global PP
global MP
global MMP
global MC
global t
t=0;
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
else
MC='0.';
MS='0.';
S='0.';
PP='0.';
MP='0.';
MMP='0.';
set(handles.Mbox,'string','');
end



% --- Executes on button press in MR.
function MR_Callback(hObject, eventdata, handles)
% hObject    handle to MR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global multiply
global divide
global plus
global minus
global S
global PP
global MMP
global t
t=0;
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif(~isempty(multiply)|~isempty(divide)|~isempty(plus)|~isempty(minus))

    set(handles.edtxt,'string','0.')

elseif (~ischar(MMP))
    
    if (fix(MMP)-MMP==0)

        set(handles.edtxt,'string',MMP)
        
        MMP=get(handles.edtxt,'string');
       
        MMP=strcat(MMP,'.');
        set(handles.edtxt,'string',MMP)
        
    else
        set(handles.edtxt,'string',MMP);
        
    end

 elseif ( ischar(MMP) & strcmp(MMP,'0.')~=1 )
    if (fix(str2double(MMP))-(str2double(MMP))==0)
        set(handles.edtxt,'string',MMP)
        MMP=get(handles.edtxt,'string');
        mmr=regexp(MMP,'[.]');
        if mmr>0
            set(handles.edtxt,'string',MMP)
        else
           
            MMP=strcat(MMP,'.');
            set(handles.edtxt,'string',MMP)
        end 
    else
        set(handles.edtxt,'string',MMP);
    end
else
    if(strcmp(S,'0.'))
        set(handles.edtxt,'string',PP);
    else
        set(handles.edtxt,'string',S);
    end
end


% --- Executes on button press in MS.
function MS_Callback(hObject, eventdata, handles)
% hObject    handle to MS (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global multiply
global divide
global plus
global minus
global MS
global S
global t
global MMP
global MMS
S=get(handles.edtxt,'string');
MS=str2double(get(handles.edtxt,'string'));
MMS=MS;
MMP='0.';
if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif(~isempty(multiply)|~isempty(divide)|~isempty(plus)|~isempty(minus))
elseif (MS~=0)
set(handles.Mbox,'string','M');
else
set(handles.Mbox,'string','');
end
t=0;


% --- Executes on button press in MP.
function MP_Callback(hObject, eventdata, handles)
% hObject    handle to MP (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global multiply
global divide
global plus
global minus
global PP
global MP
global MS
global S
global MMP
global t
global x
global MMS
i=MMP;
PP=get(handles.edtxt,'string');
MP=str2double(get(handles.edtxt,'string'));

if (strcmp(get(handles.edtxt,'string'),'Cannot divide by zero.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Invalid input for function.'))
        beep;
elseif (strcmp(get(handles.edtxt,'string'),'Result of function is undefined.'))
beep;
elseif(~isempty(multiply)|~isempty(divide)|~isempty(plus)|~isempty(minus))
 
elseif (MP~=0 & strcmp(MS,'0.')~=1)
    set(handles.Mbox,'string','M');
    if (strcmp(S,'0.')~=1 & strcmp(i,'0.'))
        MMP=(MS)+(MP);

    elseif (strcmp(S,'0.')~=1 & ~ischar(i))
        p1=str2double(get(handles.edtxt,'string'));
        MMP=MMP+p1;

    elseif(strcmp(S,'0.')~=1 & ischar(i))

            MMP=str2double(i);
            p1=str2double(get(handles.edtxt,'string'));
            MMP=MMP+p1;

    end

elseif (MP~=0 & strcmp(MS,'0.'))
    set(handles.Mbox,'string','M');
    if ( ~ischar(x)& strcmp(S,'0.')~=1 & strcmp(i,'0.'))

        MMP=(x)+(MP);

    elseif ( ischar(x)& strcmp(S,'0.')~=1 & strcmp(i,'0.'))
       
        MMP=(MP)+(MMS);
              
    elseif (strcmp(S,'0.')~=1 & ~ischar(i))
     p1=str2double(get(handles.edtxt,'string'));
        MMP=MMP+p1;
       
    elseif(strcmp(S,'0.')~=1 & ischar(i))%& strcmp(i,'0.')~=1)

            MMP=str2double(i);
            p1=str2double(get(handles.edtxt,'string'));
            MMP=MMP+p1;
    
    elseif (MP~=0 & strcmp(MS,'0.') & strcmp(S,'0.'))
       
        if (~ischar(i))
            p1=str2double(get(handles.edtxt,'string'));
            MMP=MMP+p1;
        elseif(ischar(i)& strcmp(i,'0.')~=1)
             MMP=str2double(i);
             p1=str2double(get(handles.edtxt,'string'));
             MMP=MMP+p1;
         
         else
            MMP=MP;
        
        end

    end

end
t=0;


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