Attempt to execute SCRIPT interp2 as a function:

Hi,
I a trying to run a code while I get this error.
Attempt to execute SCRIPT interp2 as a function:
/Applications/MATLAB_R2020a.app/toolbox/matlab/polyfun/interp2.m
Error in TMD_calculate (line 89)
D=interp2(X,Y,H',xt,yt);D=D';
while either there is no script and a function that both exist on this same path or there is not even a script of that overall.
I will be thankful if you let me know how I can solve that.

2 个评论

Please show us the output of this command:
which interp2 -all
which interp2.m -all
/Applications/MATLAB_R2020a.app/toolbox/matlab/polyfun/interp2.m
/Applications/MATLAB_R2020a.app/toolbox/parallel/gpu/@gpuArray/interp2.m % gpuArray method

请先登录,再进行评论。

回答(2 个)

Did you mistakenly edit interp2, and then save it, after deleting the function header?
Are you POSITIVE there is no script by that name? What happens when you do this? I'm sorry, but I've seen the claim before, and it was pretty much always wrong.
which interp2 -all
Did you download something that has an interp2 script in it?
The point being, if MATLAB tells you interp2 is a script, then MATLAB sees a script by that name. However that script was created, there is something called interp2 on your path, and it is a script. MATLAB has no reason to lie in this.

2 个评论

which interp2.m -all
/Applications/MATLAB_R2020a.app/toolbox/matlab/polyfun/interp2.m
/Applications/MATLAB_R2020a.app/toolbox/parallel/gpu/@gpuArray/interp2.m % gpuArray method
As I suspected from your comments, there is indeed a scripted version of interp2. Not an obvious one, but it was there after all. The point is, that error is impossible to arrive at, UNLESS there is a script named interp2.

请先登录,再进行评论。

Run
edit /Applications/MATLAB_R2020a.app/toolbox/matlab/polyfun/interp2
and show us what the first couple of lines look like.
The error message
Attempt to execute SCRIPT interp2 as a function:
/Applications/MATLAB_R2020a.app/toolbox/matlab/polyfun/interp2.m
tells us that MATLAB is trying to run /Applications/MATLAB_R2020a.app/toolbox/matlab/polyfun/interp2.m, but sees it as a script.

8 个评论

so I used edit /Applications/MATLAB_R2020a.app/toolbox/matlab/polyfun/interp2
and the code showed up. I ran it and I got this error again ! :
Attempt to execute SCRIPT interp2 as a function:
/Applications/MATLAB_R2020a.app/toolbox/matlab/polyfun/interp2.m
Error in interp2 (line 40)
u_interp = interp2(x, y, u(y), X, Y, 'linear');
Run
dbstop if caught error
this might catch too many errors initially, but somethings not right. interp2 (line 40) is a comment, but your error message shows a call to interp2.
Once you land in the file interp2, run
dbstack
Copy and paste the response. This will tell us where the other interp2 is being found.
The first line of interp2 should be
function Vq = interp2(varargin)
I would suggest
dbstop if error
rather than
dbstop if caught error
You mean when I get the error run dbstack? if you mean that I get this:
dbstack
> In TMD_calculate (line 89)
In TMD_calculate (line 89)
In TMD_calculate (line 89)
In helpUtils.csh/helpviewFactory/get_location_for_topic (line 60)
In helpUtils.csh/helpviewFactory/get_location_for_shortname_and_topic (line 51)
In helpUtils.csh.mapTopic (line 7)
In matlab.internal.language.introspective.getExtendedErrorCallback (line 6)
K>>
While at that break point, what does
which interp2
return? Also, what does
which -all pathdef
return?
Oh no !
It doesn't have this: function Vq = interp2(varargin)
It is opening one of my old project code but I don't know why that project is in this path! How I can get this one that you are saying in this path?
which interp2
/Applications/MATLAB_R2020a.app/toolbox/matlab/polyfun/interp2.m
which -all pathdef
/Applications/MATLAB_R2020a.app/toolbox/local/pathdef.m
My guess is that at some point your code is changing directories, specifically to the location of where the old project code lives, and is finding your interp2 (which is why MATLAB isn't finding it with which -all -- since it's not really on the MATLAB path). The solution here is to rename your interp2 to something else.
Or you have added your project to the path (but then which -all should have found it). The solution here is to edit your path to no longer include it (HOME > Set Path. Select folder, then click Remove and Save).

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by