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

4 views (last 30 days)
Hi,
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
methods
function s = eventset(datasetInput)
s = s@dataset(datasetInput);
end
end
end
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
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';
end
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.
  2 Comments
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.

Community Treasure Hunt

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

Start Hunting!