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

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 commentaire

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.

Connectez-vous pour commenter.

 Réponse acceptée

Birdman
Birdman le 2 Mar 2018
Modifié(e) : Birdman le 2 Mar 2018
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 commentaires

TemperatureCoversion is what my file name is saved as, sorry forgot to mention that! But it says I need more input arguments and I don't know what that means
You need to pass input arguments, as I did in my answer. fah is the input argument having a value of 77. Your command
TemperatureConversion
does not contain any input argument.
@Hines Ward: do not just click the big green "Run" button. This button is useless, and is the worst design decision in the history of computing. Ingore it. You need to follow the instructions that Birdman gave you.
If you do not know what the command window is or how to call function then you can learn basic MATLAB concepts by doing the introductory tutorials:
I've read these links, but heres my thought process... The User Defined Function I should be following is like this:
function [output variables] = function_name(input variables)
My output is [Celsius], and my input is the Fahrenheit! I don't understand why I would need more inputs when I only need the Fahrenheit..Im sorry I'm just not understanding! I tried not pressing the 'Run' button, instead just simply typing my file name in the command line but I still get an error saying I need more inputs
The problem is, you don't pass any input arguments to your function. Where is your input in this command?
TemperatureConversion
You see, you only typed the function, but not its input, there is no bracket after your function, which means you do not pass the input argument. How the function will know what to use as an input argument?
Stephen23
Stephen23 le 2 Mar 2018
Modifié(e) : Stephen23 le 2 Mar 2018
@Hines Ward: lets try a new perspective on this: what value are you converting from Fahrenheit to Celsius? Where is this value specified?
Ohhhhh my, I get it now.
>> TemperatureConversion(50)
ans =
10
I needed to pass the input argument like Birdman said! Thank you guys
You are welcome. These are very basic concepts, learn them well to proceed well.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Operators and Elementary Operations dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by