Function with two outputs only giving one output

16 ビュー (過去 30 日間)
Brian Wells
Brian Wells 2020 年 9 月 29 日
コメント済み: Walter Roberson 2020 年 9 月 30 日
function [C K] = FTOCK (degreeF)
%FTOCK converts degrees reading in farenheit to celcius and then kelvin
degreeF;
C=(degreeF-32)/1.8;
K=(degreeF+459.67)/1.8;
%fprintf('%.1f degrees in Farenheit Translates to %.2f degrees Celcius and %.2f degrees Kelvin\n',degreeF,C,K);
end
I do not know why this only outputs the calculated Celsius degree, K is clearly within the brackets.
  1 件のコメント
Brian Wells
Brian Wells 2020 年 9 月 29 日
I want two outputs. Coded like this it only outputs the Celsius

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

回答 (1 件)

Xingwang Yong
Xingwang Yong 2020 年 9 月 29 日
Apparently, the code is right.
I assume you are new to matlab.
You should use
[C K] = FTOCK (degreeF)
to receive two outputs instead of
c = FTOCK (degreeF)
  3 件のコメント
Xingwang Yong
Xingwang Yong 2020 年 9 月 30 日
That is weird, maybe your matlab installation is unsuccessful. You can run this snippet on other computers or matlab online, it should work on any matlab release.
Walter Roberson
Walter Roberson 2020 年 9 月 30 日
When you used
[C K] = FTOCK (degreeF)
then was there an error message, such as there not being enough outputs?
If not, then what happened when you
disp(C)
disp(K)

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

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by