Why does DISPLAY method in MATLAB 7.8 (R2009a) seem to call the builtin SIZE method?

2 views (last 30 days)
I have created a custom class Foo and has overloaded the SIZE method for it:
classdef Foo
properties
data
end
methods
function this = Foo(x)
this.data = x;
end
function res = size(this)
res = size(this.data);
end
end
end
I then create an array of Foo objects and try to find its size
v=[Foo(2) Foo(1) Foo(3)];
size(v)
The SIZE method does not work on this array, as expected and returns an error:
??? Error using ==> size
Too many input arguments.
Error in ==> Foo>Foo.size at 22
res = size(this.data);
However, the DISP method works on this array and shows that the size of the array is 1x3. I expected the DISP method to call the size method of the class and therefore error as before.
display(v)
1x3 Foo
Properties:
data
Methods

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 30 Oct 2009
The display of MATLAB objects is broken down into two categories: objects that are scalar and objects that are not. For scalar objects (as determined by mxIsScalar), display never calls SIZE. However, when you are displaying an array of Foo objects, the overloaded SIZE will be called, but in this case, it errors, is caught in the Try/Catch block, and the built-in SIZE method is used instead.

More Answers (0)

Categories

Find more on Data Type Identification in Help Center and File Exchange

Products


Release

R2009a

Community Treasure Hunt

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

Start Hunting!