why I get the error message like "Attempt to execute SCRIPT bar as a function"?

7 vues (au cours des 30 derniers jours)
balti afzal
balti afzal le 4 Déc 2023
Modifié(e) : VBBV le 4 Déc 2023
I am writing the code but in my MATLAB 2016, it's showing the error,

Réponses (2)

John D'Errico
John D'Errico le 4 Déc 2023
Don't use existing function names as the names of your own scripts. If you do, then eventually you will get strange errors like this.
Do this in MATLAB:
which bar -all
It will show you where it finds a script by that name, defined by you. Rename that script, so something not already in use.
  1 commentaire
Dyuman Joshi
Dyuman Joshi le 4 Déc 2023
In OP's case, the live editor shows the location of the script, as observed in the screenshot attached.

Connectez-vous pour commenter.


VBBV
VBBV le 4 Déc 2023
power_input = [-load -p_c] % this line uses builtin function load
  1 commentaire
VBBV
VBBV le 4 Déc 2023
Modifié(e) : VBBV le 4 Déc 2023
Change the above line since load is a built-in function and needs some input arguments when you call it in inside a bar function. Also, you probably might have named the script file with same name as bar function, then such error would appear. e.g. if the file name is bar.m

Connectez-vous pour commenter.

Catégories

En savoir plus sur Printing and Saving dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by