I have this error: ''Execution of script plot as a function is not supported: C:\Users\Jonathan e Leonardo\D​ocuments\M​ATLAB\plot​.m''

조회 수: 592 (최근 30일)
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
Steven Lord
Steven Lord 2023년 11월 3일
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
Warning: Function plot has the same name as a MATLAB built-in. We suggest you rename the function to avoid a potential name conflict.
Warning: Function plot has the same name as a MATLAB built-in. We suggest you rename the function to avoid a potential name conflict.
/tmp/tp3a79b330_05bc_42e0_8712_09c278bc7e8b/plot.m built-in (/MATLAB/toolbox/matlab/graph2d/plot) % Shadowed /MATLAB/toolbox/matlab/graphics/math/@digraph/plot.m % digraph method /MATLAB/toolbox/matlab/graphics/math/@graph/plot.m % graph method /MATLAB/toolbox/matlab/timeseries/@timeseries/plot.m % timeseries method /MATLAB/toolbox/matlab/graphics/math/@polyshape/plot.m % polyshape method /MATLAB/toolbox/matlab/graphics/math/@alphaShape/plot.m % alphaShape method /MATLAB/toolbox/matlab/bigdata/@tall/plot.m % tall method /MATLAB/toolbox/bioinfo/bioinfo/@phytree/plot.m % phytree method /MATLAB/toolbox/bioinfo/microarray/@HeatMap/plot.m % HeatMap method /MATLAB/toolbox/bioinfo/microarray/@clustergram/plot.m % clustergram method /MATLAB/toolbox/curvefit/curvefit/@cfit/plot.m % cfit method /MATLAB/toolbox/curvefit/curvefit/@sfit/plot.m % sfit method /MATLAB/toolbox/econ/econ/@conjugateblm/plot.m % conjugateblm method /MATLAB/toolbox/econ/econ/@diffuseblm/plot.m % diffuseblm method /MATLAB/toolbox/econ/econ/@mixconjugateblm/plot.m % mixconjugateblm method /MATLAB/toolbox/econ/econ/@lassoblm/plot.m % lassoblm method /MATLAB/toolbox/econ/econ/@mixsemiconjugateblm/plot.m % mixsemiconjugateblm method /MATLAB/toolbox/econ/econ/@empiricalblm/plot.m % empiricalblm method /MATLAB/toolbox/econ/econ/@blm/plot.m % blm method /MATLAB/toolbox/econ/econ/@customblm/plot.m % customblm method /MATLAB/toolbox/econ/econ/@semiconjugateblm/plot.m % semiconjugateblm method /MATLAB/toolbox/ident/ident/@iddata/plot.m % iddata method /MATLAB/toolbox/ident/nlident/@idnlarx/plot.m % idnlarx method /MATLAB/toolbox/ident/nlident/@idnlhw/plot.m % idnlhw method /MATLAB/toolbox/mpc/mpc/@mpc/plot.m % mpc method /MATLAB/toolbox/risk/risk/@varbacktest/plot.m % varbacktest method /MATLAB/toolbox/robust/rctobsolete/robust/@frd/plot.m % frd method /MATLAB/toolbox/robust/robust/@umargin/plot.m % umargin method /MATLAB/toolbox/shared/channel/rfprop/@propagationData/plot.m % propagationData method /MATLAB/toolbox/shared/drivingscenario/@drivingScenario/plot.m % drivingScenario method /MATLAB/toolbox/signal/signal/@dspdata/plot.m % dspdata method /MATLAB/toolbox/stats/bayesoptim/@BayesianOptimization/plot.m % BayesianOptimization method /MATLAB/toolbox/stats/classreg/@LinearModel/plot.m % LinearModel method /MATLAB/toolbox/wavelet/wavelet/@dtree/plot.m % dtree method /MATLAB/toolbox/wavelet/wavelet/@wdectree/plot.m % wdectree method /MATLAB/toolbox/wavelet/wavelet/@ntree/plot.m % ntree method
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
x = 1+1
I can run that script without a problem:
plot
x = 2
but if I try to call the plot function included in MATLAB I receive an error.
plot(1:10, 1:10)
Execution of script plot as a function is not supported:
/tmp/tp3a79b330_05bc_42e0_8712_09c278bc7e8b/plot.m
If I were to delete the plot.m script, I would be able to call the plot function in MATLAB.

댓글을 달려면 로그인하십시오.

채택된 답변

Alagu Sankar Esakkiappan
Alagu Sankar Esakkiappan 2022년 1월 24일
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
DGM
DGM 2023년 9월 27일
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()?

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Junran Chen
Junran Chen 2023년 12월 15일
Hi, change your file name from plot.m to another thing will work.

Xinchang
Xinchang 2024년 3월 4일
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.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by