Why does the function 'details' show more than 'disp' for objects?

1 次查看(过去 30 天)
According to the documentation, the 'details' function provides more information when the input is an object than 'disp'. However, looking at the code of 'details' (which is not a built-in function), it just invokes 'disp'. Then how can it result in a different output? Used MATLAB version: R2015b, Linux 64 bit

采纳的回答

Walter Roberson
Walter Roberson 2017-2-18
>> which -all details
/Applications/MATLAB_R2017a.app/toolbox/matlab/lang/details.m
details is a built-in method % string method
details is a built-in method % meta.PackageList method
details is a built-in method % handle method
details is a built-in method % meta.ClassList method
details is a built-in method % meta.FunctionList method
details is a built-in method % meta.TypeList method
details is a built-in method % matlab.mixin.internal.indexing.Paren method
[...]
So the disp() source you are looking at is only used for objects that do not have a more specific method.
  3 个评论
Walter Roberson
Walter Roberson 2017-2-18
编辑:Walter Roberson 2017-2-18
So the details() source you are looking at is only used for objects that do not have a more specific method.
That is, there is not just one details.m that is called for everything. When MATLAB encounters a call to details(), it first checks to see if the parameter is an object (in the Object Oriented Programming sense). If it is an object, then it checks to see if there is a details method defined for that object; if it is then it calls that details method, rather than calling the details.m that you found.
Example:
>> p = plot(rand(1,5)); which details(p)
details is a built-in method % matlab.graphics.chart.primitive.Line method
Notice that I passed p in to which, so that it can look up to find out which details() method to call for an object with the same data type as p has.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

尚未输入任何标签。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by