Function that converts Celsius to Fahrenheit and prints it to a file

38 views (last 30 days)
function Y=CelToFar(Cel)
Far=((9*Cel/5)+32);
X = [Far, Cel];
fileID = fopen('ftoc.txt','w');
fprintf(fileID,'%6s %12s\n','Far','Cel');
fprintf(fileID,'%6.2f %12.8f\n', X);
fclose(fileID);
After running I get this
CelToFar
Not enough input arguments.
Error in CelToFar (line 7)
Far=((9*Cel/5)+32);

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 29 Sep 2019
Edited: KALYAN ACHARJYA on 29 Sep 2019
Error in CelToFar (line 7)
Far=((9*Cel/5)+32);
Here it is- I assumed you pass the single aruments (scalar) at a time, if large array Cel data, also you can do that.
function X=CelToFar(Cel)
Far=(9*Cel)/5+32;
X = [Far, Cel]; % here I have changed the output arguments as X, as you defined initially
Save the function in new Matlab file (save it name as CelToFar.m). Now call the function from another Matlab main script or commnad window-
>> result=CelToFar(20)
result =
68 20
I hope rest you can do the print..
Good Luck!

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!