tan function giving an error

1 回表示 (過去 30 日間)
Richard O'Sullivan
Richard O'Sullivan 2018 年 10 月 28 日
回答済み: Star Strider 2018 年 10 月 28 日
x = (-pi/2)+0.01:0.01:(pi/2)-0.01; plot(x,tan(x)), grid on
gives an error: Array indices must be positive integers or logical values. but changing tan to either sin or cos does not give an error. Code above is from MATLAB.

採用された回答

Star Strider
Star Strider 2018 年 10 月 28 日
Your code works when I run it.
That you are getting the error: ‘Array indices must be positive integers or logical values.’ leads me to believe that you have a variable named ‘tan’ in your workspace. This is called ‘overshadowing’ a function.
To find out, run this from your Command Window or a script:
which tan -all
If the first result is:
tan is a variable.
You have found the problem. You then have to rename the ‘tan’ variable to something meaningful, and so the name does not ‘overshadow’ any MATLAB functions.

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by