Borrar filtros
Borrar filtros

How create a calculator function ?

23 visualizaciones (últimos 30 días)
sths
sths el 11 de Feb. de 2015
Comentada: Vennmukhil T el 8 de Sept. de 2019
Create a function calculator() that has as input: a: number; b: number; t: textfield containing the mathematical function to perform. The functions to calculate are: “+” “-“ “*” “/”. If another type of function is inputted (e.g. “^”) the output should be NaN. Tip: to verify a text you can use the function “strcmp”. You will also have to use an “if else” statement in your code. Create a proper header.
How do you do this?
  3 comentarios
James Tursa
James Tursa el 11 de Feb. de 2015
Contributors to this site are willing to help, but are generally not willing to do your homework for you. Please make an attempt and if you can't get it working, post your code and ask specific questions about your code and we will help.

Iniciar sesión para comentar.

Respuestas (2)

Rick Rosson
Rick Rosson el 11 de Feb. de 2015
Here is a start:
function y = calculator(a,b,t)
% Insert your header comments here
%
%
% insert your MATLAB code here:
end
  1 comentario
John D'Errico
John D'Errico el 11 de Feb. de 2015
Oh, gosh. That gives the whole thing away. :)

Iniciar sesión para comentar.


sths
sths el 12 de Feb. de 2015
Editada: Guillaume el 12 de Feb. de 2015
a=4
b=2
if strcmp(t,'+')
y(a,b)=6
elseif strcmp(t,'-')
y(a,b)=2
elseif strcmp(t,'*')
y(a,b)=8
elseif strcmp(t,'/')
y(a,b)=2
elseif strcmp(t,'^')
y(a,b)=NaN
save(calculator,a,b,t)
function y = calculator(a,b,t)
What am i doing wrong here?
  1 comentario
Vennmukhil T
Vennmukhil T el 8 de Sept. de 2019
Function keyword use is actually invalid

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by