Why am I getting a parse error?

4 ビュー (過去 30 日間)
Matthew Adams
Matthew Adams 2018 年 10 月 26 日
編集済み: James Tursa 2018 年 10 月 26 日
I am getting a parse error at the h variable for a basic HW problem.
h = input('Please input the water height.');
if h >= 0 && h <= 40
vcone = pi*10^2*15;
r = sqrt((2*(25/2))-(h^2));
vsphere = ((h*pi)/6)*((3*r^2)+(h^2));
vtot = vcone + vsphere;
disp(vtot)
else
disp('The water height was invalid')
end

回答 (1 件)

James Tursa
James Tursa 2018 年 10 月 26 日
Please post the complete error message text, along with the offending line. I can only guess that maybe you have a variable named "input" that is shadowing the MATLAB "input" function.
  2 件のコメント
Matthew Adams
Matthew Adams 2018 年 10 月 26 日
I closed and restarted the program, and now there is no error. I'm not sure what it could have been.
James Tursa
James Tursa 2018 年 10 月 26 日
編集済み: James Tursa 2018 年 10 月 26 日
It was probably exactly what I stated ... that you had a variable called "input" that was shadowing the MATLAB "input" function. When you closed and restarted MATLAB, that cleared that "input" variable. You could have also manually cleared the "input" variable to fix this.
Learning Opportunity: Don't name variables the same as important MATLAB functions, like "input" or "sum" etc.

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by