Is it possible to write a class that inherits from timetable?

4 次查看(过去 30 天)
Hi. I would like to write a class that inherits from the timetable class, so that I can write my own methods (e.g. for manipulating and graphing time-series data). Is there any way to do this? Attempting to do so using:
classdef mySubClass < timetable
gives the error:
Class 'timetable' is Sealed and may not be used as a superclass.
Specifically, I'm not seeking to modify the base timetable class. I simply want to inherit from it and extend it with some specific attributes/methods.
  3 个评论
lyra
lyra 2021-8-12
Thanks, yes - this is a possible workaround. Matlab's timeseries object is also built on timetable and can be inherited from. However, both of these solutions involve an extra layer of nesting (which is superfluous for my use-case). As this object will be a foundational data structure for what could end-up being a very large toolbox, I'd much rather avoid if I can. Will continue to search (and hope) for a solution for now.
J. Alex Lee
J. Alex Lee 2021-8-12
If you go the route suggested by @Jeff Miller and want to be able to directly access the timetable properties from your "wrapper" without having to reference the property containing the timetable itself, you could also inherit from dynamicproperties and kind of "automatically" expose the timetable properties by duplicating them as dynamic properties in your "wrapper" class, and then write a generic setter/getter for them.
not perfect, but it's one way...

请先登录,再进行评论。

回答(1 个)

Prahlad Gowtham Katte
Hello,
As per my understanding of the query, you are trying to inherit a sealed class which is not possible. For your case though as suggested in the comments you can use a timetable as a property and add methods on that.
The following link is attached as reference to non-inheritance property of sealed class
Hope it helps

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by