OOP - Sealed Superclasses

9 views (last 30 days)
Peter Cook
Peter Cook on 30 Jan 2018
Answered: Tibor Auer on 29 Jun 2021
I am trying to create a custom class to overload the MATLAB image object but am getting this error message:
Class 'matlab.graphics.primitive.Image' is Sealed and may not be used as a superclass
Is there a list of [graphics] objects in The MathWorks documentation which are not "sealed?"
Or should I start from the beginning with
classdef overloadedImage < handle

Accepted Answer

Steven Lord
Steven Lord on 30 Jan 2018
"Is there a list of [graphics] objects in The MathWorks documentation which are not "sealed?" "
No, there is no such list.
"I am trying to create a custom class to overload the MATLAB image object "
Can you say a little more about why you're trying to overload the image object? Perhaps you can already do what you want and you're just not aware of how to do it, or perhaps this could be worthy of an enhancement request?
  4 Comments
Steven Lord
Steven Lord on 29 Jun 2021
Since this question was asked, we added the capability to create your own chart classes. It may not meet all your needs, but take a look at this section of the documentation for more information.
Peter Cook
Peter Cook on 29 Jun 2021
@Steven Lord It has been quite some time since I asked this, and I haven't tried out any new MATLAB features. For the application for which this question/capability was relevant we had a number of axes containing heatmap-like data, timeseries data, and depth-series data. The data sources were independent of one another but the axes limits (e.g. depth/time) were bound to one another so that manipulation of one resulted in the need to resample the underlying datasets and re-display them in a "timely" manner (no perceptible latency). The image processing toolbox and MATLAB image object (imagesc unusable due to data gaps) were quite useful in the development phase. Ultimately we wound up with some lightweight MATLAB classes (each window pane essentially implementing a virtual class that contains some sort of dataset, has as a classmember an axes handle, and a method for drawing itself) that subscribed to change events on the x/y axes and wrote a bunch of C MEX Files to do the image manipulation. That code has been in production for a while but if we ever revisit it, I will be sure to evaluate the custom chart classes.

Sign in to comment.

More Answers (2)

Tibor Auer
Tibor Auer on 28 Jun 2021
I have a similar issue with graph class, which is also Sealed. I would like to extend its funcionality by adding further methods and proprties.
  4 Comments
Tibor Auer
Tibor Auer on 29 Jun 2021
The main extension is to add methods to calulate the line of the graph and some further methods supporting the calculation.
I have also added some customised plotting as a method, which also adapts to when the graph is a line of a graph.
Peter Cook
Peter Cook on 29 Jun 2021
@Tibor Auer I think your approach should work, but perhaps attempting to extend the builtin MATLAB graph class isn't wholly appropriate in this case because it looks like what you actually want is to modify hggraphics/plotting objects. MATLAB's graph object is used to describe/manipulate data that is defined by 2-tuples of vertices and edges (and other metadata). Maybe that's what you are actually doing here and I misunderstand your code sample.
Martin said a class should be "open for extension, but closed for modification" but that doesn't mean TMW has to listen to him :)

Sign in to comment.


Tibor Auer
Tibor Auer on 29 Jun 2021
@Peter Cook, There might be some misunderstanding. "Line of graph" is not about plotting but transforming: Line graph - Wikipedia

Categories

Find more on Construct and Work with Object Arrays 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!