Attempt to execute SCRIPT plot as a function,how to solve it?

3 次查看(过去 30 天)
Attempt to execute SCRIPT plot as a function
  2 个评论
dpb
dpb 2024-12-2
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.

请先登录,再进行评论。

回答(1 个)

John D'Errico
John D'Errico 2024-12-2
编辑:John D'Errico 2024-12-2
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.)

类别

Help CenterFile Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by