Attempt to execute SCRIPT plot as a function,how to solve it?
2 views (last 30 days)
Show older comments
Attempt to execute SCRIPT plot as a function![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1816793/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1816793/image.png)
2 Comments
dpb
on 2 Dec 2024
You've named another m-file script as plot; you chose plot2 for this one, but even that is prone to making the mistake; I'd suggest choosing/using a name descriptive of your purpose to avoid accidentally doing it again in the future.
Try
which -all plot
and it will show you all the plot() functions the system can find; all of them should be in the base MATLAB \toolbox or other MATLAB folders; it will then also show you the one you have created; make sure it isn't something you really need to keep; if it's just a mistake, then delete it, otherwise rename it to something else.
Answers (1)
John D'Errico
on 2 Dec 2024
Edited: John D'Errico
on 2 Dec 2024
Don't name your script plot.
In general, don't use existing names of supplied functions for your own functions or scripts. You can do so of course, but then you have the unhappy result of needing to ask here what happened.
If you don't think you did this, do this test at the command prompt:
which plot -all
You will find that indeed, you have named a script with the name plot. Yes, it seemed like a logical thing to do, since you wanted to plot, but it confuses MATLAB. And computers are so easily confused. (It could have been worse of course. You might have decided to name your code SkyNet, or something like that. I don't want to think of what may have gone wrong then.)
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!