Are MATLAB built-in function scripts editable?

조회 수: 5 (최근 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 CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by