Clear Filters
Clear Filters

How to make a subclass of dataset class be displayed in Variables Editor in the same way as datasets objects are displayed

3 views (last 30 days)
I try to build an eventset object which subclasses dataset class. I'd like to subclass dataset (among others) because of the nice way in which it is displayed in Variables Editor (good for quick data inspection). The problem is that when I do this the display is lost and eventset object is displayed just as a plain matrix or cell array. If you know workaround for this issue please help :-)
Here's the code that defines eventset class:
classdef eventset < dataset
function s = eventset(datasetInput)
s = s@dataset(datasetInput);
Then I do the following:
evSet = eventset({magic(3), 'Var1', 'Var2', 'Var3'});
dtSet = dataset({magic(3), 'Var1', 'Var2', 'Var3'});
and when I view both created variables in Variables Editor then evSet looks like a plain matrix, and I would like it to look just as dtSet does.
If you know a way to solve it or if you know why this is impossible :-), then please let me know.
  1 Comment
Julian on 13 Jul 2012
Thanks for bringing this up. I don't know a solution but was thinking of sub-classing dataset myself. While we use R2011a right now later releases have a nicer variable editor display for dataset, and losing that by sub-classing is a big disadvantage. I would have hoped that the variable editor display followed the inheritance principle like display, i.e. display the same as the parent unless the display method is specialised.

Sign in to comment.

Answers (1)

Daniel Shub
Daniel Shub on 4 Jul 2012
The variable editor makes use of com.mathworks.mlservices.MLArrayEditorServices and the formatting parts seem to be proprietary. One work around, which will likely cause all sorts of problems is to add a class method to your object that lies about the class name
function classname = class(obj)
classname = 'dataset';
While it could theoretically be a static method since obj is not used, com.mathworks.mlservices.MLArrayEditorServices doesn't call class in a way that this would work.
Michal on 4 Jul 2012
Thanks but this won't work or it will work but only partially.
If I define such class method then indeed Variables Editor gets stupified and displays eventset as dataset.
However, the new issue is that the same class method is called every time any method is called. So if I add some custom method custommethod to eventset object then calling eventset.cutomethod raises an exception because Matlab thinks this is a dataset class object which does NOT have cutommethod method.
Anyway thanks for the tip. At least I got to know of com.mathworks.mlservices.MLArrayEditorServices.
Daniel Shub
Daniel Shub on 4 Jul 2012
I said it would cause all sorts of problems. The biggest problem I see is that openvar is not going to know how to display any new properties that you add to eventset. Therefore I cannot see any reason to go down this road. That said, you can get around the problem of defining new methods by defining a subsref method. That is a related, but new question.
If you think that my answer was useful, then please consider voting for it.

Sign in to comment.


Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!