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

2 visualizzazioni (ultimi 30 giorni)
Attempt to execute SCRIPT plot as a function
  2 Commenti
Fahima Sarmin
Fahima Sarmin il 2 Dic 2024
Modificato: Fahima Sarmin il 2 Dic 2024
error in the command window, how to solve it?
dpb
dpb il 2 Dic 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.

Accedi per commentare.

Risposte (1)

John D'Errico
John D'Errico il 2 Dic 2024
Modificato: John D'Errico il 2 Dic 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.)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by