MATLAB Simple Calculator using switch case statement [PROGRAM]

Veröffentlicht am: 26 September 2018
auf dem Kanal: MR MJT
2,214
32

how to make simple calculator using switchcase statement in matlab
Youtube Channel:    / @mrmjt  

LIKE US!!
FACEBOOK PAGE:
  / smartnquickacademy  

matlab code for simple calculator
scientific calculator using matlab gui
gui based calculator in matlab
calculator project in matlab
matlab calculator function
how to write a calculator in matlab
how to use matlab as a calculator
how to make a scientific calculator using matlab

CODE:
function calculator
figure('Position',[200 200 220 200],'Name','Calculator','NumberTitle','off','MenuBar','None','Resize','off');
txt=uicontrol('Style','Text','Position',[10 165 200 30],'String','0');
global stack value top op tops opstack num1 num2 flag;
flag=0;
x=10;
y=130;
top=1;
tops=1;
name=['7','8','9','/','4','5','6','*','1','2','3','-','0','+','C','='];%k


for k=1:size(name,2)

uicontrol('Style','Pushbutton','Position',[x y 50 30],'String' ,name(k),'Callback',@arithmetic) ;
x=x+50;
if(mod(k,4)==0)

x=10;y=y-35;

end
end
function arithmetic(object,~)
num=str2double(get(object,'String'));
if((numgreaterthan=0)&&(numsmallarthan=9))
value=num;
evaluate();
else
op=get(object,'String');
if(op=='C')
top=1;
tops=1;
set(txt,'String','0');
else
operator();
end
end
end

function evaluate()
stack(top)=value;
if((stack(1)==0)&&(top==2))
stack(1)=stack(top);
top=top-1;
end
str=num2str(stack(1));
for i=2:top
str=strcat(str,num2str(stack(i)));
end
top=top+1;
set(txt,'String',' ');
set(txt,'String',str);
flag=0;
end
function operator()

if((top~=1)||(flag==1))

opstack(tops)=op;
tops=tops+1;

if((tops==2)&&(flag~=1))

str=num2str(stack(1));
for i=2:top-1
str=strcat(str,num2str(stack(i)));
end
num1=str2double(str);
flag=1;
top=1;
elseif(topsgreater than or=3)

if(flag==0)
str=num2str(stack(1));
for i=2:top-1
str=strcat(str,num2str(stack(i)));
end
num2=str2double(str);


top=1;

if(opstack(tops-1)=='=')

calculate();
set(txt,'String',' ');
set(txt,'String',num2str(num1));

flag=1;
tops=1;




else

calculate();
set(txt,'String',' ');
set(txt,'String',num2str(num1));

flag=1;
tmp=opstack(tops-1);
opstack(1)=tmp;
tops=tops-1;
end
else
tmp=opstack(tops-1);
opstack(1)=tmp;
tops=tops-1;

end
end

end
end


function calculate()
switch (opstack(1))
case '+'
num1=num1+num2;
case '-'
num1=num1-num2;
case '/'
num1=num1/num2;
case '*'
num1=num1*num2;


end
end

end


Auf dieser Seite können Sie das Online-Video MATLAB Simple Calculator using switch case statement [PROGRAM] mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer MR MJT 26 September 2018 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 2,214 Mal angesehen und es wurde von 32 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!