Problem with built in and interp1

1 次查看(过去 30 天)
All, I'm having an issue that built in cant find the native interp1 function, see code below:
% initialsie
x = [0:0.1:2*pi];
% run a check on syntax and method:
default = sin ( x );
check = builtin ( 'sin', x );
% is it equal? It should be:
isequal ( default, check )
% now I try the same for interp1
default2 = interp1 ( x, check , pi/2 )
% try the same with the builtin command:
check2 = builtin ( 'interp1', x, check, pi/2 );
??? Error using ==> builtin
Cannot find builtin function 'interp1'
Computer details: Windows XP - r2010b
Is this expected behaviour? Is it repeated on other versions/platforms?
I have interp1 overloaded - because the inbuilt interp1 has poor error messages - but I want to be able to run the built in one to verify that the results of the two are the same (automated testing), the only way I can think to do it other than built in is to remove the path to the overloaded one - but it would mean a lot of rmpath, addpath etc.... So I'd like a neater solution...
Thanks

采纳的回答

Jan
Jan 2012-11-21
编辑:Jan 2012-11-21
interp1 is not a built-in function, but an M-file. Therefore you observe the expected and wanted behaviour.
See:
which interp1 -all
which sin -all
  5 个评论
Jan
Jan 2012-11-21
编辑:Jan 2012-11-21
It is strictly recommended not to overload Matlab's toolbox functions. While overloading them might be useful for the one or other program from the userland, it can be a desaster, when the overloaded function is called from other funcrions of Matlab. Then the different behaviour is a severe cause of errors.
We find corresponding examples in this forum: Somebody overlaoded display() and this function is called from any line, which is not terminated by a semicolon. I had overloaded STRCMP and made a small mistake. Afterwards neither opening the function in the editor, nor shutting down Matlab worked anymore. Killing Matlab and fixing the Matlab path while it is off has been the only chance to start it again.
Therefore the problem of calling the toolbox version of INTERP1 instead of a user-defined one is very easy: Rename the later under all circumstances.
To be sure that such overloading does not happen accidently, e.g. when a new Matlab version contains a function, which was not known when the user created an own function, append folders with user-defined functions at the end of the PATH only. Never, never, never add them before Matlab's own toolbox function. Exception: You are really sure, that you want to replace a function e.g. by a bugfix.
Robert Cumming
Robert Cumming 2012-11-21
Yes I understand (and agree) - however I found that I was getting repeatedly asked why interp1 was crashing for users - so I made a copy and updated the error messages only.
Thanks for your help Jan

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by