Create a MATLAB program (utilizing a temp-conversion function) that prints out,
ID: 3553231 • Letter: C
Question
Create a MATLAB program (utilizing a temp-conversion function) that prints out, on a clear screen, a table of temperatures. Randomly generate 20 Celsius temperatures between -50 and 150 degrees. Your temp-conversion function should determine the Fahrenheit, Rankine, Celsius and Kelvin equivalents of the input temperature. Provide a header for your table which includes your name,and date. Skip a line and print out 'Temperature Comparison and Comfort ', centered. Skip two lines then provide column headers of Celsius, Kelvin, Fahrenheit, Rankine and Comfort. (Abbreviate if necessary) Celsius should be integer display, Kelvin: one decimal; Fahrenheit: 2 decimals; Rankine: 1 decimal. Numbers in columns should be aligned. The 'comfort' column should display text as follows: temperatures at or below 32 F are 'freeze'; >32F and <=55F: 'cold'; >55F and <=70F: 'mild'; > 70F and <90F: 'warm'; >90F and <=105F: 'hot'; >105F: '!!!'.
Explanation / Answer
%%The code has been written to produce the output in command window....:)
clc;
fprintf('Name - xxxxx ');
fprintf('Date - 28/03/2014 ');
N= 20; %no of random temperature instances
temp_c = zeros(1,N); %celcius
temp_F = zeros(1,N); %fahrenhiet
temp_R = zeros(1,N); %Rankine
temp_K = zeros(1,N); %Kelvin
fprintf('Celcius');
fprintf(' Kelvin');
fprintf(' Fahrenhiet');
fprintf(' Rankine');
fprintf(' Comfort ');
for i=1:N
temp_c(i) = -50 + 200 * rand();
temp_F(i) = temp_c(i)*9/5 + 32;
temp_R(i) = (temp_c(i)+ 273.15)*9/5 ;
temp_K(i) = temp_c(i) + 273.15;
fprintf('%4.0f',temp_c(i));
fprintf(' %.1f',temp_K(i));
fprintf(' %.2f',temp_F(i));
fprintf(' %.1f ',temp_R(i));
if temp_F(i) <= 32
fprintf('Freeze ');
end
if temp_F(i) >32 && temp_F(i) <= 55
fprintf('Cold ');
end
if temp_F(i) >55 && temp_F(i) <= 70
fprintf('Mild ');
end
if temp_F(i) >70 && temp_F(i) <= 90
fprintf('Warm ');
end
if temp_F(i) >90 && temp_F(i) <= 105
fprintf('Hot ');
end
if temp_F(i) > 105
fprintf('!!! ');
end
end