How to Convert Fahrenheit to Celsius

48 ビュー (過去 30 日間)
Pu Andaes
Pu Andaes 2020 年 10 月 2 日
コメント済み: Walter Roberson 2024 年 9 月 22 日
function deg_ce = fa_to_ce(deg_f)
deg_ce = (5/9)*(deg_f-32);
fprintf('the temp is %f\n', deg_ce)
end
If i run it, it says that there aren't enough input arguments?
  2 件のコメント
David Hill
David Hill 2020 年 10 月 2 日
How are you running it?
c=fa_to_ce(10);
Rik
Rik 2020 年 10 月 2 日
You forgot to tag this as homework. I have just done so for you.

サインインしてコメントする。

回答 (4 件)

Pratibha
Pratibha 2023 年 5 月 24 日
temperature = input('Please enter the temperature: ');
units = input('Please enter the units of Temperature (C or F): ','s');
if (units == 'F' || units == 'f')
converted = (temperature-32)*(5/9);
convertedto = 'C';
elseif (units == 'C' || units == 'c')
converted = temperature*(9/5) + 32;
convertedto = 'F';
else
fprintf('\nYou have given a wrong input\n')
fprintf('The program will restart again\n')
fprintf('----------RESTART - FCF.M --------- \n\n')
fcf
end
fprintf('%.2f %s = %.2f %s\n',temperature, upper(units),converted,convertedto)
  3 件のコメント
DGM
DGM 2023 年 5 月 24 日
switch lower(units) % makes tests case-insensitive
case {'f','fahrenheit'} % you can support synonymous cases
% do things
case {'c','celsius','centigrade'}
% do things
otherwise
error('unknown units %s',units) % error() and warning() are things
end
... would be a start.
Rik
Rik 2023 年 5 月 24 日
And in case of less drastic changes: using strcmp instead of == also solves most issues.

サインインしてコメントする。


Bhavani
Bhavani 2023 年 1 月 13 日
disp('This program convert Celsius to Fahrenheit');
Celsius=input('Write a temperature in Celsius and you''ll have the result in Fahrenheit: ');
disp([ 'x = ' num2str(Celsius) ' Celcius and y = ' num2str(Celsius*1.8+32) ' Fahrenheit'])

Image Analyst
Image Analyst 2023 年 1 月 13 日
Your code already works as long as you pass it a value. Observe:
celsius = fa_to_ce(212) % Convert 212 F to C
The temperature is 100.000000 degrees Celsius.
celsius = 100
celsius = fa_to_ce(32) % Convert 32 F to C
The temperature is 0.000000 degrees Celsius.
celsius = 0
function deg_ce = fa_to_ce(deg_f)
deg_ce = (5/9)*(deg_f-32);
fprintf('The temperature is %f degrees Celsius.\n', deg_ce)
end
Your problem was almost certainly that you were just clicking the green Run triangle. If you do that then nothing can possibly get passed in to the argument list and so you get the error you got. You need to call it from a script or the command line and you need to pass in the value in degrees F.

Kaltum
Kaltum 2024 年 9 月 22 日
how can i use matlab to convert degrees celsius to farenheit
  1 件のコメント
Walter Roberson
Walter Roberson 2024 年 9 月 22 日
syms deg_ce deg_f
eqn = deg_ce == (5/9)*(deg_f-32)
solve(eqn, deg_f)
So the formula is 9/5 * deg_ce + 32

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSources についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by