Need some help with my function, why do I keep getting an error?

조회 수: 3 (최근 30일)
T.Y. Hilton
T.Y. Hilton 2018년 3월 2일
댓글: Birdman 2018년 3월 2일
I am supposed to write a function that accepts temperature in degrees Fahrenheit(°F) and returns the corresponding value in degrees Celsius (°C). Here is my code:
function [Celsius] = TemperatureConversion(Fahrenheit)
Celsius = (5/9)*(Fahrenheit-32);
When I run this code, I get this:
>> TemperatureConversion
Not enough input arguments.
Error in TemperatureConversion (line 12)
Celsius = (5/9)*(Fahrenheit-32);
Why am I getting this error?
  댓글 수: 1
Stephen23
Stephen23 2018년 3월 2일
Error in TemperatureConversion (line 12)
Why does the error message say line 12? You showed us two lines of code: this tells us that the code you have shown us is not the complete code in the file that you are trying to run, so we have no idea what you are actually trying to do.

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

채택된 답변

Birdman
Birdman 2018년 3월 2일
편집: Birdman 2018년 3월 2일
You should save the function in a m file and then call it from command line as:
fah=77;
degree=TemperatureConversion(fah)
You need to read this documentation carefully.
  댓글 수: 8
T.Y. Hilton
T.Y. Hilton 2018년 3월 2일
Ohhhhh my, I get it now.
>> TemperatureConversion(50)
ans =
10
I needed to pass the input argument like Birdman said! Thank you guys
Birdman
Birdman 2018년 3월 2일
You are welcome. These are very basic concepts, learn them well to proceed well.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by