tan function giving an error

1 view (last 30 days)
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.

Accepted Answer

Star Strider
Star Strider on 28 Oct 2018
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.

More Answers (0)

Tags

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!