Customize display of an enumeration class

5 ビュー (過去 30 日間)
Sam Roberts
Sam Roberts 2014 年 7 月 11 日
編集済み: Neha Talnikar 2014 年 7 月 23 日
I'd like to customize the display of an enumeration class using matlab.mixin.CustomDisplay .
If I have a regular (non-enumeration) class such as the following:
classdef test < handle & matlab.mixin.CustomDisplay
properties
value
end
methods
function obj = test(value)
obj.value = value;
end
end
methods (Access = protected)
function displayScalarObject(obj)
disp(['hello ', num2str(obj.value)])
end
end
end
then everything works fine - for example,
>> a = test(1)
a =
hello 1
But if I have an enumeration class such as the following (note the addition of the enumeration block):
classdef test < handle & matlab.mixin.CustomDisplay
properties
value
end
methods
function obj = test(value)
obj.value = value;
end
end
methods (Access = protected)
function displayScalarObject(obj)
disp(['hello ', num2str(obj.value)])
end
end
enumeration
enum1(1)
end
end
then the display is not customized - for example,
>> a = test.enum1
a =
enum1
Using the debugger, I can see that my displayScalarObject method is never called. Implementing other methods of matlab.mixin.CustomDisplay such as displayNonScalarObject and so on doesn't seem to help - these never get called either.
What's going on? Do disp and display work differently for enumeration classes, in such a way that anything that's overridden by matlab.mixin.CustomDisplay just gets ignored?
Is there a way to get a customized display with matlab.mixin.CustomDisplay , but using an enumeration class?
PS I am able to directly overload disp and/or display on an enumeration class that does not inherit from matlab.mixin.CustomDisplay , and this works fine. But I'm looking to use matlab.mixin.CustomDisplay if possible.

採用された回答

Neha Talnikar
Neha Talnikar 2014 年 7 月 23 日
編集済み: Neha Talnikar 2014 年 7 月 23 日
I tried your code and run into the same issue. It seems that this cannot be done.
However, you can override the “disp” and/or “display” in an enumeration class and implement the required code in it.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCustomize Object Display for Classes についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by