Can someone help me with my code? with an example

6 ビュー (過去 30 日間)
Tony Hill
Tony Hill 2014 年 4 月 27 日
コメント済み: Vernon Niioku 2017 年 11 月 26 日
Can someone show me an example of a function that receives a temperature in degrees Fahrenheit ( F ) as input argument, and returns the temperature in both degrees Celsius ( C ) and degrees Kelvin ( K ), in this order.
Im so stuck on this last question
  3 件のコメント
Tony Hill
Tony Hill 2014 年 4 月 27 日
Function CK = convertFahrenheit(F)
C(1,:) = 5/9 *(F-32); K(2,:) = C + 273.15;
Vernon  Niioku
Vernon Niioku 2017 年 11 月 26 日
C(1,:) = 5/9 *(F-32); K(2,:) = C + 273.15;

サインインしてコメントする。

回答 (3 件)

Jos (10584)
Jos (10584) 2014 年 4 月 27 日
Write a function like this
function CK = convertFahrenheit (F)
% CONVERTFAHRENHEIT - converts temperature
%
% CK = CONVERTFAHRENHEIT (F) concerts the temperature value(s) F, measured in Fahrenheit to
% the corresponding temperatures in degrees Celsius (first column of CK) and
% Kelvin (second column of CK).
CK(1,:) = F(:)-32 ... ; % conversion to degrees Celsius
CK(2,:) = CK(1,:) - 273.13 % conversion to Kelvin

Tony Hill
Tony Hill 2014 年 4 月 27 日
ok question am i supposed to add those elipses into the code itself. Im so confused with this problem its stressing me out very much
  1 件のコメント
Image Analyst
Image Analyst 2014 年 4 月 28 日
編集済み: Image Analyst 2014 年 4 月 28 日
No, those are line continuation "signals" or indicators. Use it when you have a very long line and you want to continue it on the next line. Normally it's the last thing on a line, though you can have a comment after it if you want, but not code like you did. Jos used them to indicate that that is where you're supposed to complete the code. He didn't do it all for you and you should know the formulas, so replace the ... with the actual code. It's your homework, not his so he didn't do it all for you. You have to finish it.

サインインしてコメントする。


Tony Hill
Tony Hill 2014 年 4 月 27 日
Function CK = convertFahrenheit(F) [C,K]
C(1,:) = 5/9 *(F-32); K(2,:) = C + 273.15;
heres my attempt im stuck
  1 件のコメント
Jos (10584)
Jos (10584) 2014 年 4 月 28 日
You want to store the result in the single variable CK, not in two separate variables C and K
You can concatenate two variables into a single one afterwards
CK = [C K]
or you can fill the columns of CK more directly:
CK(:,1) = ..
CK(:,2) = ..
I strongly suggest you start reading the Getting Started section of the documentation, though, to learn about variables and their meaning.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by