Question

In: Computer Science

Please answer this using MATLAB (Not c or c++) and make sure to provide proper commenting:...

Please answer this using MATLAB (Not c or c++) and make sure to provide proper commenting:

a. Write a function that writes a series of random Fahrenheit temperatures and their corresponding Celsius temperatures to a tab-delimited le. Use 32 to 212 as your temperature range.
From the user, obtain the following:
1) The number of temperatures to randomly generate.
2) The name of the output file.

b. Write a function that reads a file produced by part (a). Focusing only on the Celsius temperatures in the le, calculate and display to screen the following:
1) Mean or Average
2) Minimum
3) Maximum

Solutions

Expert Solution

MATLAB Code:

(a)

File: randomTemperature.m

function randomTemperature()
    % Function that generates random Fahrenheit temperatures and converts and writes Celsius values to file
    fileName = input(" Please enter the name of your file: ");
    iterCnt = input(" Please enter the number of iterations: ");
  
    % Opening file for writing
    fileID = fopen(fileName,'w');
  
    % Min and Max range
    minRange = 32;
    maxRange = 212;
  
    % Printing header
    fprintf(fileID, " Fahrenheit Celsius");
  
    % Iterating over given number of iterations
    for i = 1:iterCnt
      
        % Generating Fahrenheit temperature
        fhTemp = minRange+rand(1)*(maxRange-minRange);
      
        % Converting into Celsius using conversion formula
       celTemp = ( (5/9.0) * ( fhTemp - 32.0 ) );
      
        % Writing to file
        fprintf(fileID, "\n %.2f \t %.2f ", fhTemp, celTemp);
  
    endfor
  
    % Closing file
    fclose(fileID);

endfunction

Sample Run:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

(b)

File: temperatureStatistics.m

function temperatureStatistics()
    % Function that reads Celsius temperatures and prints Average, max and min values
  
    % Opening file for reading
    fid = fopen("temperatures.txt", "r");

    % Reading header
    header = fgets(fid);
  
    % Reading values
    values = fscanf(fid, "%f");

    % Closing file
    fclose(fid);
  
    % Extracting Celsius values
    celsiusTemperatures = values(2:2:end);
  
    % Printing Statistics
    printf("\n Average Celsius Temperature: %.2f \n", mean(celsiusTemperatures) );
    printf("\n Minimum Celsius Temperature: %.2f \n", min(celsiusTemperatures) );
    printf("\n Maximum Celsius Temperature: %.2f \n", max(celsiusTemperatures) );

endfunction

Sample Run:


Related Solutions

Graphical User Interfaces using java. Please provide proper commenting so that I understant what is going...
Graphical User Interfaces using java. Please provide proper commenting so that I understant what is going on in the program: Develop a simple tool for analyzing a segment of text that determines the number of words in that segment and the average word length. The application should have a single window with a scrolling text box (JTextArea) and an area to display the statistics. The statistics area should be a panel with a titled border, containing labeled fields that display...
Review the following squestions and provide substantive responses. Make sure that you provide proper references and...
Review the following squestions and provide substantive responses. Make sure that you provide proper references and format the paper in the APA style. 1. Suppose you are having difficulty managing a small group of subordinates who work in an office 1,000 miles away from your home base. What kinds of changes in structure, technology, and people can be implemented to more closely supervise these distant employees? 2. Think of the organization in which you currently work—specifically, the work group or...
Computer Science: Please be sure to make sure answer is legible if answer is written. :)...
Computer Science: Please be sure to make sure answer is legible if answer is written. :) Prove that a complement of any finite set of binary strings F has a decidable membership. Will such F always be recursive?
Computer Science: Please be sure to make sure answer is legible if answer is written. :)...
Computer Science: Please be sure to make sure answer is legible if answer is written. :) Prove that for any positive integer k, the open line segment (1/2k+1, 1/2k) contains uncountably many real numbers. You must apply Cantor’s diagonalization directly, i.e., you cannot base your proof on the fact that the line segment (0, 1) contains uncountably many reals (hint: think in binary).
Computer Science: Please be sure to make sure answer is legible if answer is written. :)...
Computer Science: Please be sure to make sure answer is legible if answer is written. :) Is the set of total Boolean-valued functions, i.e., those whose range is T or F, countable? Prove your answer.
Using java, commenting should be proper, along with testing for valid and invalid inputs: Develop a...
Using java, commenting should be proper, along with testing for valid and invalid inputs: Develop a simple tool for analyzing a segment of text that determines the number of words in that segment and the average word length. The application should have a single window with a scrolling text box (JTextArea) and an area to display the statistics. The statistics area should be a panel with a titled border, containing labelled fields that display the number of words in the...
Answer the following questions using TRUE, FALSE or UNCERTAIN. Make sure you provide a brief explanation...
Answer the following questions using TRUE, FALSE or UNCERTAIN. Make sure you provide a brief explanation for each of your answers. Your score will largely reflect the quality and relevance of your explanation. (i) In the IS-LM model, equilibrium output is determined in the goods market, while equilibrium interest rate is determined in the bond market. (ii) A $100 million increase in defense spending will have the same impact on equilibrium output as does a $100 million tax cut.
Please circle the answer and please make sure that it is true answer. 1-)A physical pendulum...
Please circle the answer and please make sure that it is true answer. 1-)A physical pendulum consists of a meter stick that is pivoted at a small hole drilled through the stick a distance d from the 50 cm mark. The period of oscillation is 2.24 s. Find d (in cm's).
Please circle the answers and please make sure that it is true answer. Thank you. A...
Please circle the answers and please make sure that it is true answer. Thank you. A particle executes linear SHM with frequency 0.11 Hz about the point x = 0. At t = 0, it has displacement x = 0.33 cm and zero velocity. For the motion, determine the (a) displacement at t = 2.2 s, and (b) velocity at t = 2.2 s.
Please Use C language to Make a calculator. Make sure calculator is able to take up...
Please Use C language to Make a calculator. Make sure calculator is able to take up to 5 values. Try to make calculator using simple coding As you can. Please create a simple calculator with only +, -,* and divide. It has to be able to enter any numbers (including decimals) and be able to do the following functions: +, -, divide and multiply. Please have the answers, always rounded to two decimal figures. The calculator will also have to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT