Azzera filtri
Azzera filtri

Celsius to Fahrenheit or vice versa

42 visualizzazioni (ultimi 30 giorni)
Riri
Riri il 20 Gen 2014
Spostato: DGM il 2 Mag 2024
Creating a program to convert Celsius to Fahrenheit
  2 Commenti
CJ Grucza
CJ Grucza il 9 Gen 2020
Spostato: DGM il 2 Mag 2024
I am able to convert fahrenheit to celsius but i am having a problem with converting celsius to fahrenheit. Why?
Walter Roberson
Walter Roberson il 9 Gen 2020
Spostato: DGM il 2 Mag 2024
We don't know given that little information.
T*9/5+32

Accedi per commentare.

Risposta accettata

Amit
Amit il 21 Gen 2014
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'])
  1 Commento
Amit
Amit il 21 Gen 2014
For both cases:
disp('This program convert Celsius to Fahrenheit');
val = input('Type 1 for Celcius to Farenheit and Type 2 for vice versa: ');
switch val
case 1
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']);
case 2
Faren=input('Write a temperature in Farenheit and you''ll have the result in Celcius: ');
disp([ 'x = ' num2str(Faren) ' Fahrenheit and y = ' num2str((Faren-32)/1.8) ' Celcius ' ]);
end

Accedi per commentare.

Più risposte (2)

Diego
Diego il 12 Dic 2022
function [y] = farenheit(C)
y = 9/5 *C + 32;
%farenheit is the name of the file

DGM
DGM il 30 Dic 2022
Modificato: DGM il 30 Dic 2022
@Diego is on the right track. Instead of harrassing the user for all inputs interactively, just write a basic function that can be used programmatically. Besides the exercise in writing functions, this is just a simple linear transformation.
C = [-40 0 100 1000];
F = ctof(C)
F = 1×4
-40 32 212 1832
C1 = ftoc(F)
C1 = 1×4
-40 0 100 1000

Categorie

Scopri di più su Audio Processing Algorithm Design in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by