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

采纳的回答

John D'Errico
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 个评论
NAVNEET NAYAN
NAVNEET NAYAN 2017-4-11
yeah, it's working but it opens in command window. how can i view it in editor...
Thanks
John D'Errico
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
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
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
Jan 2017-4-12
I install Matlab with admin privileges and work as standard user. Then overwriting built-in function is not possible.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by