Error in buit in function

12 views (last 30 days)
Mo BO
Mo BO on 10 May 2016
Commented: Walter Roberson on 10 May 2016
i get error in built in function and i can't find out why and while trying to figure it out, i looked it up in the help and took the same example and then executed it in the command windows after trying the code i always get the same error ,but if cleared the work space and tried the example again before trying the code it works well it looks like the code make some thing wrong with the matlab *
  3 Comments
Walter Roberson
Walter Roberson on 10 May 2016
Yup, clearly they have created double.m and put it on their path.
Mo BO
Mo BO on 10 May 2016
yes i have,but how is that effecting the built in function.I did't even call it or use it in by code

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 10 May 2016
When you created double.m in a local directory, and put the local directory on the path, that affected most calls to double(). MATLAB mostly finds appropriate routines by name: it usually starts at the beginning of the MATLAB path and looks for a double() in each directory until it finds one. It does not matter that the first routine you invoke does not call double(): that routine invokes another routine that does call double(), and the double.m that you put on the path now overrides the built-in double() routine.
You should not name your .m files the same as any Mathworks-provided routine unless you want your routine to be called instead of the Mathworks provided routine.
  4 Comments
Mo BO
Mo BO on 10 May 2016
ok,but why when i clear work space this problem is eliminated if i directly used the built in function in the command window and appear again in if tried it also in the command window but after executing the code ? and how i can know the names that matlab already use to avoid it
Walter Roberson
Walter Roberson on 10 May 2016
Your function might be changing the MATLAB path.
To see if any particular name is in use for a function, use
which TheNameToCheck
for example
which image
which doublefactorial
The second of those turns out not to be used (but there is a MuPAD double factorial function named fact2)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!