필터 지우기
필터 지우기

How create a calculator function ?

조회 수: 23 (최근 30일)
sths
sths 2015년 2월 11일
댓글: Vennmukhil T 2019년 9월 8일
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
James Tursa
James Tursa 2015년 2월 11일
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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Rick Rosson
Rick Rosson 2015년 2월 11일
Here is a start:
function y = calculator(a,b,t)
% Insert your header comments here
%
%
% insert your MATLAB code here:
end
  댓글 수: 1
John D'Errico
John D'Errico 2015년 2월 11일
Oh, gosh. That gives the whole thing away. :)

댓글을 달려면 로그인하십시오.


sths
sths 2015년 2월 12일
편집: Guillaume 2015년 2월 12일
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
Vennmukhil T
Vennmukhil T 2019년 9월 8일
Function keyword use is actually invalid

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by