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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de Feb. de 2017
>> 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 comentarios
Walter Roberson
Walter Roberson el 18 de Feb. de 2017
Editada: Walter Roberson el 18 de Feb. de 2017
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.
Zoltán Csáti
Zoltán Csáti el 18 de Feb. de 2017
Now it is clear. Thank you for explaining.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Aún no se han introducido etiquetas.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by