Thread Subject: Creating subclass of MATLAB graphical object(class?)?

Subject: Creating subclass of MATLAB graphical object(class?)?

From: Kesh

Date: 20 Mar, 2009 21:32:01

Message: 1 of 4

Does anyone here know whether it is possible (if so, how) to create a MATLAB class that is a subclass of one of graphical objects? For instance,

classdef arc < line
...
end

to define a subclass of line and its object to be drawn in an axes.

I was hoping the above syntax to work, but apparently "line" is not a class (no constructor available) although if you evaluate "class(handle(line))" returns "line"

Does anybody here have any ideas to realize this idea?

Thanks,
Kesh

Subject: Creating subclass of MATLAB graphical object(class?)?

From: per isakson

Date: 21 Mar, 2009 15:22:01

Message: 2 of 4

"Kesh " <tikuma@hotmail.removethis.com> wrote in message <gq120h$ckq$1@fred.mathworks.com>...
> Does anyone here know whether it is possible (if so, how) to create a MATLAB class that is a subclass of one of graphical objects? For instance,
>
> classdef arc < line
> ...
> end
>
> to define a subclass of line and its object to be drawn in an axes.
>
> I was hoping the above syntax to work, but apparently "line" is not a class (no constructor available) although if you evaluate "class(handle(line))" returns "line"
>
> Does anybody here have any ideas to realize this idea?
>
> Thanks,
> Kesh

I'm pretty sure that
1. there is no documented way to do it
2. the idea (or close) can be realized with a classes that have handle graphic objects as properies.

/per

Subject: Creating subclass of MATLAB graphical object(class?)?

From: Kesh

Date: 21 Mar, 2009 17:38:01

Message: 3 of 4

> > Does anyone here know whether it is possible (if so, how) to create a MATLAB class that is a subclass of one of graphical objects? For instance,
> >
> > classdef arc < line
> > ...
> > end
> >
> > to define a subclass of line and its object to be drawn in an axes.
> >
> > I was hoping the above syntax to work, but apparently "line" is not a class (no constructor available) although if you evaluate "class(handle(line))" returns "line"
> >
> > Does anybody here have any ideas to realize this idea?
>
> I'm pretty sure that
> 1. there is no documented way to do it
> 2. the idea (or close) can be realized with a classes that have handle graphic objects as properies.

Yeah, that's what I was afraid of. I knew of (1) as I've done a quite bit of reading and searching for the possibilities. I will try to use handle (actually, hgsetget) class as its superclass as suggested in (2).

What I want is in two folds:
1. The object of the derived arc class can be appended to the axes object's Children list, and
2. Parent object of the associated line object to be reassigned from the axes to the object of the derived arc class.

If any of the roaming Mathworks staff has inside info on this, I'd love to know if there is a hidden solution to this problem.

Thanks,
Kesh

Subject: Creating subclass of MATLAB graphical object(class?)?

From: bradphelan

Date: 23 Mar, 2009 19:26:26

Message: 4 of 4

On Mar 21, 6:38 pm, "Kesh " <tik...@hotmail.removethis.com> wrote:
> > > Does anyone here know whether it is possible (if so, how) to create aMATLABclass that is asubclassof one of graphical objects? For instance,
>
> > > classdef arc < line
> > > ...
> > > end
>
> > > to define asubclassof line and its object to be drawn in an axes.
>
> > > I was hoping the above syntax to work, but apparently "line" is not a class (no constructor available) although if you evaluate "class(handle(line))" returns "line"
>
> > > Does anybody here have any ideas to realize this idea?
>
> > I'm pretty sure that
> > 1. there is no documented way to do it
> > 2. the idea (or close) can be realized with a classes that have handle graphic objects as properies.
>
> Yeah, that's what I was afraid of. I knew of (1) as I've done a quite bit of reading and searching for the possibilities. I will try to use handle (actually, hgsetget) class as its superclass as suggested in (2).
>
> What I want is in two folds:
> 1. The object of the derived arc class can be appended to the axes object's Children list, and
> 2. Parent object of the associated line object to be reassigned from the axes to the object of the derived arc class.
>
> If any of the roaming Mathworks staff has inside info on this, I'd love to know if there is a hidden solution to this problem.
>
> Thanks,
> Kesh


I don't come past CSSM too often these days ( hi Per ),

I think it will work but you just need to use the package prefix 'hg'
for all your handle graphics
base classes. See the following code snippet ripped from the file
exchange. It doesn't do
what you want but gives away the names that Mathworks uses for the
handle graphics
classes. It still might not work though. I don't have a copy of Matlab
handy to test it
out. Let us know how it goes.

From

http://www.mathworks.com/matlabcentral/fileexchange/19877?controller=file_infos&download=true

----

% Ensure hObj is valid target
handleObj = handle(hObj);
if ~ishandle(hObj)
  error('MAKEDATATIP:InvalidHandle',...
    'HOBJ is an invalid handle object.');
elseif ~isa(handleObj,'hg.surface') &&...
    ~isa(handleObj,'hg.patch') &&...
    ~isa(handleObj,'hg.line') &&...
    ~isa(handleObj,'hg.image')
  error('MAKEDATATIP:InvalidObjectType',...
    'Objects of class ''%s'' are not a valid targets for
datatips.',...
    class(handleObj));
end

--

Brad Phelan
http://xtargets.com

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
oop Kesh 20 Mar, 2009 17:35:06
graphics Kesh 20 Mar, 2009 17:35:06
class Kesh 20 Mar, 2009 17:35:06
inheritance Kesh 20 Mar, 2009 17:35:06
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com