# Matlab Help: Creating M-File

• Mar 24th 2010, 03:13 PM
lvelazquez83
Matlab Help: Creating M-File
I need help creating three M-files for the following equations so I can input the data into tables.

Fahrenheit (Tf), Celcius (Tc), Kelvins (Tk) and Rankine (Tr)

Tf = Tr - 459.67R

Tf = 9/5Tc + 32F

Tr = 9/5Tk

I need to do this so i can make conversion tables for Fahrenheit to Kelvins, Celcius to Rankine and Celcius to Fahrenheit.

• Mar 24th 2010, 07:10 PM
lvelazquez83
I created the following M-Files:

Fahrenheit_to_Kelvin
F = input ('Enter the values for Fahrenheit:');
Kelvin = (F + 459.67).*(5/9)

How do I generate a table for this M-File for values 0 to 200 with increments of 20? I also need to have this transpose into two columns.

Celcius_to_Rankine
Enter values for Celcius:[0:20:200,Rankine]

• Mar 24th 2010, 08:12 PM
lvelazquez83
I think i got it! Does this look corrent?

>> Fahrenheit_to_Kelvin
Enter the values for Fahrenheit:0:20:200
Kelvin =
Columns 1 through 5
255.3722 266.4833 277.5944 288.7056 299.8167
Columns 6 through 10
310.9278 322.0389 333.1500 344.2611 355.3722
Column 11
366.4833

>> Table1 = [(0:20:200)', Kelvin']
ans =
0 255.3722
20.0000 266.4833
40.0000 277.5944
60.0000 288.7056
80.0000 299.8167
100.0000 310.9278
120.0000 322.0389
140.0000 333.1500
160.0000 344.2611
180.0000 355.3722
200.0000 366.4833

But now i have ran into a new problem:

I have to create a table with a title, column headings and correct spacing. whenever i try this the formular ends up all messed up. this is what i type in and this is what i get in return:

>> Fahrenheit_to_Kelvin
Enter the values for Fahrenheit:0:20:200
Fahrenheit to Kelvin
Fahrenheit, F Kelvin, K
0.00 20.00
40.00 60.00
80.00 100.00
120.00 140.00
160.00 180.00
200.00 255.37
266.48 277.59
288.71 299.82
310.93 322.04
333.15 344.26
355.37 366.48

if you notice column one is doubled

here is my M-File:

F = input ('Enter the values for Fahrenheit:');
Kelvin = (F + 459.67).*(5/9);

disp(
'Fahrenheit to Kelvin');

disp(
'Fahrenheit, F Kelvin, K');
fprintf (
'%8.2f %10.2f\n',table1)

I just put in whatever values for the spacing, not worried about that at the moment. Any thoughts?