How can I configure , so that MATLAB will not allow duplicate built in function by re-definition ?
Show older comments
MATLAB(7.5.0) has some built in functions when some body is Overwriting it by another defination in Matlab Command Window, it is allowing and meaning is changing, Somecases it is giving absurd result & some cases it is giving errors for Overwrite.
for Example:
>> M = magic(3)
M =
8 1 6
3 5 7
4 9 2
>> result = -det(M)
result =
360
>> det =1
det =
1
>> result= -det(M)
??? Index exceeds matrix dimensions.
MATLAB(7.5.0) has some built in functions when some body is Overwriting it by another defination in Matlab Command Window, it is allowing and meaning is changing, Somecases it is giving absurd result & some cases it is giving errors for Overwrite.
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 7 Feb 2013
Edited: Azzi Abdelmalek
on 7 Feb 2013
det is a Matlab function. when you do
det=1
you are creating a new variable det, and shadows the function det. To restore it
clear det
det(M)
6 Comments
M.K.H. CHANDAN
on 7 Feb 2013
Edited: M.K.H. CHANDAN
on 7 Feb 2013
Image Analyst
on 7 Feb 2013
Wow, interesting, though if you had to do that for every single function, it would be a nightmare. Best to avoid the need to do that, unless you really did need to run two functions with the same name, a built in one, and one of your own making - though I can't imagine a situation where you'd need to do that instead of picking a custom name, even if it's a wrapper function. Like my wrapper function msgboxw() which is just uiwait(msgbox(message)).
Walter Roberson
on 8 Feb 2013
builtin() is needed for OOP, but in my estimation is not usually a good solution for other circumstances.
But practicality wins sometimes. For example if people need a bigger display area on questdlg() and they need to affect existing code and it is expensive to rewrite that code, then they might pop in their own guestdlg() and builtin() within it.
Rewriting is the better approach, but "time is money". And besides, one might need to affect code written by another party, in which case the cost of rewriting over several releases of their software might be discouraging.
Jan
on 8 Feb 2013
Do not shadow builtin or clear...
M.K.H. CHANDAN
on 26 Jun 2013
Edited: M.K.H. CHANDAN
on 18 May 2015
Categories
Find more on Mathematics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!