# How to display functions with 2 outputs

53 visualizzazioni (ultimi 30 giorni)
Methat il 16 Apr 2024
Commentato: Methat il 16 Apr 2024
I am confused on how to display functions with 2 outputs, for my unit converter I need to display the output and the unt of that output an example would be 32 F but I cant seem to figure it out.
Basically it has to ensure the function returns both the converted value (numout) along with the unit relating to this output number (unit).
a = input('Please enter a number ');
disp("Select what conversion you want to do:")
disp('1. Celsius to Fahrenhiet')
convtype = input("Please enter the conversion type: ");
switch convtype
case 1
conversion = 'cels2fahr';
end
myunitconv(a, conversion)
function [numout, unit] = myunitconv(numin, convtype)
if strcmp(convtype,'cels2fahr')
numout = (numin*(9/5))+32;
unit = ;
else
error('Invalid conversion type')
end
end
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

VBBV il 16 Apr 2024
a = 212% input('Please enter a number ');
a = 212
disp("Select what conversion you want to do:");
Select what conversion you want to do:
disp('1. Celsius to Fahrenhiet')
1. Celsius to Fahrenhiet
convtype = 1 %input("Please enter the conversion type: ");
convtype = 1
switch convtype
case 1
conversion = 'cels2fahr';
end
413.6F
function [numout, unit] = myunitconv(numin, conversion)
if strcmp(conversion,'cels2fahr')
numout = (numin*(9/5))+32;
unit = 'F';
else
error('Invalid conversion type')
end
end
##### 2 CommentiMostra NessunoNascondi Nessuno
VBBV il 16 Apr 2024
you can add more cases and correspnding units (inside the function) to display the answer and unit as output
Methat il 16 Apr 2024
Thanks! I understand how it works now I was just missing the unit so just by adding it will actually print the unit value now.

Accedi per commentare.

### Categorie

Scopri di più su Numeric Types 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