I have this error: ''Execution of script plot as a function is not supported: C:\Users\Jonathan e Leonardo\Documents\MATLAB\plot.m''
514 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
JONATHAN LAZZARESCHI
el 21 de En. de 2022
Comentada: DINESH PRASAD REDDY
el 23 de En. de 2025 a las 4:11
I have this error: ''Execution of script plot as a function is not supported:
C:\Users\Jonathan e Leonardo\Documents\MATLAB\plot.m''
How can I resolve it?
7 comentarios
Steven Lord
el 3 de Nov. de 2023
Use which -all on the name that MATLAB says was a script that you expected to be a function. More likely than not you've defined your own file with the same name as a function in MATLAB or another MathWorks product and so your file is shadowing (taking precedence over) the function in the MathWorks product. Rename your file or remove it.
As an example, if I created a script file plot.m:
% Change to a new temporary directory into which I can write the file
newlocation = tempname;
mkdir(newlocation)
cd(newlocation)
% Create the file using low-level file I/O functions
fid = fopen(fullfile(pwd, 'plot.m'), 'wt');
fprintf(fid, "x = 1+1");
fclose(fid);
and ask what plot refers to:
which -all plot
I see the script I just created is the first item on the list. [I also receive warnings.]
You can see that the plot.m file MATLAB finds first is the one I created:
type plot.m
I can run that script without a problem:
plot
but if I try to call the plot function included in MATLAB I receive an error.
plot(1:10, 1:10)
If I were to delete the plot.m script, I would be able to call the plot function in MATLAB.
Respuesta aceptada
Alagu Sankar Esakkiappan
el 24 de En. de 2022
Hi Jonathan,
Aforementioned error occurs as plot is already an internal implemented function in MATLAB. You may check if there is any internal implementation already done for any specific function using which commmand:
which plot -all
This problem can be resolved by using a different filename for the current script, which is not already used for any other internal function in MATALB.
6 comentarios
DGM
el 27 de Sept. de 2023
Nobody knows what your filenames/path are, what errors you're seeing, or what you tried to do to fix it. It's up to you to describe the problem you have.
Is the error the same error as in the title? If so, what's the output of which()?
Más respuestas (2)
Junran Chen
el 15 de Dic. de 2023
Hi, change your file name from plot.m to another thing will work.
2 comentarios
Xinchang
el 4 de Mzo. de 2024
Hi, Jonathan,
I had the same issue which has been solved now. The reason is that he name of my script is plot.m which same as one of the MATLAB function (plot) names. After I change it the output is normal. You can change the script name like test.m and try again.
0 comentarios
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!