Help writing script for problem.

Problem: Ask user to enter a temperature matrix that has 3 rows and 5 columns. Columns represent average temperature in Fahrenheit from 2006 to 2010 and rows represent months from January to March as shown in the following matrix
January
February
March
2006
2007
2008
2009
2010
Once they enter all the information, convert all the temperatures in Celsius and display them as shown below
Actual Program Output
Enter the values of average temperatures in Fahrenheit from 2006 to 2010 for the months of January to March in a 5x3 matrix. Rows represent month while columns represent year
[12 34 45 67 12;54 36 45 98 76;12 43 54 78 98]
Average values of temperatures in Celsius are as follows
January
-------
2006 2007 2008 2009 2010
-11 1 7 19 -11
February
-------
2006 2007 2008 2009 2010
12 2 7 37 24
March
-------
2006 2007 2008 2009 2010
-11 6 12 26 37
I am stuck!
Please help!
I think I am on the right path but I don't know were to go from here. I am a bit confused!
% Program will convert Fahrenheit Temperatures to Celsius from 2006 to 2010
% for the months of January to March.
% User will enter a temperature matrix that has 3 rows and 5 colums.
% Columns will represent the average temperature.
fprintf('Enter the values of average temperatures in Fahrenheit from 2006 to 2010 for the months of\n')
fprintf('January to March in a 5x3 matrix. Rows represent month while columns represent year\n')
fprintf('\n[12 34 45 67 12;54 36 45 98 76;12;43;54;78;98]\n')
fprintf('\nAverage Values of temperatures in Celsius are as follows\n')
fprintf('\nJanuary\n')
fprintf('\n-------\n')
fprintf('\n2006 2007 2008 2009 2010\n')
input = F
C = (F - 32) .* 5/9

4 commentaires

Fangjun Jiang
Fangjun Jiang le 9 Sep 2011
please format your code as {}code and tell WHERE are you stuck.
Walter Diolosa
Walter Diolosa le 9 Sep 2011
% Program will convert Fahrenheit Temperatures to Celsius from 2006 to 2010
% for the months of January to March.
% User will enter a temperature matrix that has 3 rows and 5 colums.
% Columns will represent the average temperature.
fprintf('Enter the values of average temperatures in Fahrenheit from 2006 to 2010 for the months of\n')
fprintf('January to March in a 5x3 matrix. Rows represent month while columns represent year\n')
fprintf('\n[12 34 45 67 12;54 36 45 98 76;12;43;54;78;98]\n')
fprintf('\nAverage Values of temperatures in Celsius are as follows\n')
fprintf('\nJanuary\n')
fprintf('\n-------\n')
fprintf('\n2006 2007 2008 2009 2010\n')
input = F
C = (F - 32) .* 5/9
I am stuck here. I don't really know how to write the equation for it to be solved with the inputs.
Walter Roberson
Walter Roberson le 10 Sep 2011
What you have,
C = (F - 32) .* 5/9
is fine for converting farhenheit to celcius.
Walter Diolosa
Walter Diolosa le 10 Sep 2011
Hello Walter,
How would I go about setting up the script to take inputs and output the needed info. I know how to do a matrix but I don't know how to input data for a output.

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
Walter Roberson le 9 Sep 2011

0 votes

Please do not use a variable named "input", as that conflicts with the important MATLAB routine named "input"... a routine that, in fact, you should be considering invoking right there.

1 commentaire

Walter Diolosa
Walter Diolosa le 10 Sep 2011
F = input
is what I meant.
I am trying to set it up to ask for the inputs to the matrices and try to come up with a formula to calculate the output but I don't understand how to do it. I have looked at the tutorials, Textbook Matlab A practical introduction to programing and problem solving, internet searches but I am still totally confused. This is my second class and I am new to this. Thanks for some input in advance.

Connectez-vous pour commenter.

Walter Diolosa
Walter Diolosa le 11 Sep 2011

0 votes

I figured out the Matlab script needed for the output wanted.
Here it is!
% Program will convert Fahrenheit Temperatures to Celsius from 2006 to 2010
% for the months of January to March.
% User will enter a temperature matrix that has 3 rows and 5 colums. % Columns will represent the average temperature.
fprintf('Enter the values of average temperatures in Fahrenheit from 2006 to 2010 for the months of\n') fprintf('January to March in a 5x3 matrix. Rows represent month while columns represent year\n\n'); FTempmat= input('');
Cmat = round((FTempmat - 32) .* 5/9);
fprintf('\nAverage Values of temperatures in Celsius are as follows\n')
fprintf('\nJanuary\n')
fprintf('\n-------\n')
fprintf('\n 2006 2007 2008 2009 2010\n')
disp(Cmat(1,:))
fprintf('\nFebuary\n')
fprintf('\n-------\n')
fprintf('\n 2006 2007 2008 2009 2010\n')
disp(Cmat(2,:))
fprintf('\nMarch\n')
fprintf('\n-------\n')
fprintf('\n 2006 2007 2008 2009 2010\n')
disp(Cmat(3,:))
It works GREAT!

Catégories

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by