Defining the constant inside else if statement.

9 ビュー (過去 30 日間)
Josh Ueda
Josh Ueda 2020 年 4 月 11 日
コメント済み: Josh Ueda 2020 年 4 月 11 日
I am trying to create the function that includes 'if else if statement', and inside of that function I want to create the constant value, but I do not want to declare it as the variable. Here is the code that I wrote but keeps giving me the bug.
----Code-----
function Psat = fcn(Tsat)
%Calculate the saturation pressure
%Input: Temperature [C]
%Output: Pressure[MPa]
if Tsat > 2
a=1;
elseif Tsat <= 2
a=2;
end
Psat = a*Tsat
end
  4 件のコメント
Image Analyst
Image Analyst 2020 年 4 月 11 日
Do you mean you have a bug, or an error? What are you passing in for Tsat that give the error or demonstrates the bug? You aren't just clicking the green "Run" triangle to execute the code are you? Because doing that will not "invent" some value to pass into fcn(). You need to tell it what to pass in in your script, like this:
Psat = fcn(5);
Josh Ueda
Josh Ueda 2020 年 4 月 11 日
I figured out
Thanks,

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by