フィルターのクリア

Are MATLAB built-in function scripts editable?

4 ビュー (過去 30 日間)
Bob Li
Bob Li 2011 年 12 月 28 日
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

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 12 月 28 日
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 件のコメント
Bob Li
Bob Li 2011 年 12 月 29 日
Walter,
I think I understand your answers now. Thanks very much.
Bob
Titus Edelhofer
Titus Edelhofer 2011 年 12 月 29 日
OP stands for Original Poster ...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by