how can we see the inner programming of any function??
조회 수: 25 (최근 30일)
이전 댓글 표시
i am using the function "gradient". i want to see it's inner programming. can i see it.
thanks
Navneet nayan
댓글 수: 0
채택된 답변
John D'Errico
2017년 4월 11일
편집: John D'Errico
2017년 4월 11일
You often cannot see code. Much of MATLAB is provided as compiled code. This gives you efficient code, which of course you want very much. The MathWorks does NOT provide the source code for compiled tools, unless you work there.
Other tools that are written in m-files are viewable. NEVER use edit to examine code, as too often people mistakenly edit the code, then save it without realizing they did so. That will introduce random bugs into the code, a terribly bad thing to do because you will never expect to find an error there, so you will never look for it there. Therefore my recommendation that you never use edit to view code. (In fact, I saw this exact same problem happen quite recently. A user had a supplied function that appeared to be no longer working properly. The problem was they had mistakenly edited the function when looking at it, and then saved it.)
Instead, use the type command. For example, if you want to see how the nlinfit tool (from the stats toolbox) is written, then view it like this:
type nlinfit
If the function was provided in compiled form, then all that will be shown will be the block of help as returned by the help command.
댓글 수: 2
John D'Errico
2017년 4월 11일
편집: John D'Errico
2017년 4월 11일
You don't want to do that!!!!!! You CAN use edit, but that is a bad idea. I can tell you that you will be sorry, but people tend not to listen to advice, until they learn the hard way why it was good advice.
Mark Twain said this: "Good judgement is the result of experience and experience the result of bad judgement." It applies here. :)
You can scroll the command window as easily as you can scroll the editor.
추가 답변 (1개)
Steven Lord
2017년 4월 11일
The gradient function is implemented as a MATLAB function file, so you can view it. If it's read-only in your installation (to prevent the possibility of modifying it) you can edit it. If it's writable, you may want to type or dbtype it instead to avoid accidental modification.
Note that not all functions in MathWorks products are implemented as MATLAB script, function, or class files. Particularly for the built-in functions, if you want to see their source code your first step would need to be here.
댓글 수: 3
Steven Lord
2017년 4월 11일
I believe I remember that in the past we did offer that as an option in the Installer. I don't know off the top of my head if that's now the default (because of where MATLAB gets installed, it might be at least on Windows.) The installation documentation doesn't mention it, so it might be.
Jan
2017년 4월 12일
I install Matlab with admin privileges and work as standard user. Then overwriting built-in function is not possible.
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!