Are MATLAB built-in function scripts editable?

5 vues (au cours des 30 derniers jours)
Bob Li
Bob Li le 28 Déc 2011
Hi,
I have some questions with MATLAB function scripts.
First, how can I know which .m script file under C:\Program Files\MATLAB\ corresponds to the function being executed? For example, randn().
Second, if I search for “randn” under C:\Program Files\MATLAB\, there are four files under four different folders:
(1) C:\Program Files\MATLAB\R2008a\toolbox\compiler\mcr\matlab\elmat Empty
(2) C:\Program Files\MATLAB\R2008a\toolbox\matlab\elmat\ja Invalid text
(3) C:\Program Files\MATLAB\R2008a\toolbox\eml\lib\matlab\elmat valid text, code
(4) C:\Program Files\MATLAB\R2008a\toolbox\matlab\elmat valid text, help
(4) seems to be the help document which is shown after typing “help randn” in the command window, and any change (with Administrator account which has no access restriction) in its contents will be reflected when typing “help randn” again.
However, changing (3) (with Administrator account which has no access restriction) has no effect and command window commands or text editor scripts including randn() still executes normally.
So I guess MATLAB has compiled code of .m scripts stored elsewhere and actually executes them when a function is being called, so that even if the users deletes all .m codes, all related functions could still be executed normally?
This seems also prevents the user from modifying the default behavior of built-in function; if I want a slightly-modified version of built-in functions, then I need to copy it to a new location, modify its content, change its name, and then add the new location to the search folder or set as current folder. Is this correct?
Bob

Réponses (1)

Walter Roberson
Walter Roberson le 28 Déc 2011
which -all randn
For me it shows
built-in (/opt/matlab7_ng/toolbox/matlab/randfun/randn)
/opt/matlab7_ng/toolbox/matlab/randfun/@RandStream/randn.mexa64 % RandStream method
/opt/matlab7_ng/toolbox/matlab/randfun/@RandStream/randn.m % RandStream method
There is no .m corresponding to built-in functions, and the randn.m only contains the help information for the binary randn.mexa64 that has priority.
toolbox\eml is Embedded MATLAB, which is not the randn normally used.
If you want a slightly modified version of the built-in functions, put the modified version earlier on the path (still dangerous as other routines might pick it up); or use OOP and class methods so that your modified version is only used in restricted circumstances. Renaming and so on is a very good idea.
If something shows up as built-in then you are not likely to be able to get the source for it (at least not their source.) (There are a few exceptions, a few packages for which C or C++ code is provided.)
  7 commentaires
Bob Li
Bob Li le 29 Déc 2011
Walter,
I think I understand your answers now. Thanks very much.
Bob
Titus Edelhofer
Titus Edelhofer le 29 Déc 2011
OP stands for Original Poster ...

Connectez-vous pour commenter.

Catégories

En savoir plus sur Software Development Tools dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by