Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Subclass MATLAB's graphics objects

Subject: Subclass MATLAB's graphics objects

From: R Wat

Date: 28 Oct, 2010 13:44:04

Message: 1 of 5

For my research, the format of my plots is very specific and I would like to set up some default plotting procedures which abide by the formatting I must follow. Basically I need to make some modifications to the default style of the figure axes produced by matlab (i.e. whenever MATLAB calls a plotting function such as plot, surf etc. I want to have my axes used instead of the default MATLAB ones). For some of the properties, I can just use the following command

set(0,'Default...',value,...)

but some properties that I need to the axes can't be set this way (I have to add some arrows and other annotations). So, I was thinking of subclassing MATLAB's axes class and modifying the constructor so that when axes is called, it produces my axes instead and uses different default values. I've tried making a new subclass of axes as follows

classdef myAxes < axes
...
end

but I get the following error

"The specified super-class 'axes' contains a parse error or cannot be found on
MATLAB's search path, possibly shadowed by another file with the same name."

which makes me think that the classname for MATLAB's axes graphics object is not "axes" or that the axes class is protected.

This may not be the best way to go about doing this, but it is all that I could come up with. Does anyone have any ideas on how to produce my own default axes whenever a plotting routine is called?

Thanks!

Subject: Subclass MATLAB's graphics objects

From: per isakson

Date: 28 Oct, 2010 14:40:03

Message: 2 of 5

"R Wat" <rhino7890@aol.com> wrote in message <iabun4$jij$1@fred.mathworks.com>...
> For my research, the format of my plots is very specific and I would like to set up some default plotting procedures which abide by the formatting I must follow. Basically I need to make some modifications to the default style of the figure axes produced by matlab (i.e. whenever MATLAB calls a plotting function such as plot, surf etc. I want to have my axes used instead of the default MATLAB ones). For some of the properties, I can just use the following command
>
> set(0,'Default...',value,...)
>
> but some properties that I need to the axes can't be set this way (I have to add some arrows and other annotations). So, I was thinking of subclassing MATLAB's axes class and modifying the constructor so that when axes is called, it produces my axes instead and uses different default values. I've tried making a new subclass of axes as follows
>
> classdef myAxes < axes
> ...
> end
>
> but I get the following error
>
> "The specified super-class 'axes' contains a parse error or cannot be found on
> MATLAB's search path, possibly shadowed by another file with the same name."
>
> which makes me think that the classname for MATLAB's axes graphics object is not "axes" or that the axes class is protected.
>
> This may not be the best way to go about doing this, but it is all that I could come up with. Does anyone have any ideas on how to produce my own default axes whenever a plotting routine is called?
>
> Thanks!

There is no documented way to subclass handle graphic objects.

http://undocumentedmatlab.com/ might describe a work around.

You can make an Axes class that has a handle graphic object as a property.

/ per

Subject: Subclass MATLAB's graphics objects

From: Donn Shull

Date: 16 Dec, 2010 17:50:25

Message: 3 of 5

"per isakson" <poi.nospam@bimDOTkthDOT.se> wrote in message <iac203$1t0$1@fred.mathworks.com>...
> "R Wat" <rhino7890@aol.com> wrote in message <iabun4$jij$1@fred.mathworks.com>...
> > For my research, the format of my plots is very specific and I would like to set up some default plotting procedures which abide by the formatting I must follow. Basically I need to make some modifications to the default style of the figure axes produced by matlab (i.e. whenever MATLAB calls a plotting function such as plot, surf etc. I want to have my axes used instead of the default MATLAB ones). For some of the properties, I can just use the following command
> >
> > set(0,'Default...',value,...)
> >
> > but some properties that I need to the axes can't be set this way (I have to add some arrows and other annotations). So, I was thinking of subclassing MATLAB's axes class and modifying the constructor so that when axes is called, it produces my axes instead and uses different default values. I've tried making a new subclass of axes as follows
> >
> > classdef myAxes < axes
> > ...
> > end
> >
> > but I get the following error
> >
> > "The specified super-class 'axes' contains a parse error or cannot be found on
> > MATLAB's search path, possibly shadowed by another file with the same name."
> >
> > which makes me think that the classname for MATLAB's axes graphics object is not "axes" or that the axes class is protected.
> >
> > This may not be the best way to go about doing this, but it is all that I could come up with. Does anyone have any ideas on how to produce my own default axes whenever a plotting routine is called?
> >
> > Thanks!
>
> There is no documented way to subclass handle graphic objects.
>
> http://undocumentedmatlab.com/ might describe a work around.
>
> You can make an Axes class that has a handle graphic object as a property.
>
> / per

Several Notes:

1. Handle Graphics uses MATLABs internal object which is undocumented.

2. You can obtain the handle object from the numeric handle using the handle function. ie:

>> a = axes

a =

  9.7656e-004

>> ah = handle(a)
 
ah =
 
axes

3. The handle object obtained this way is different from a handle object created with MATLABs new and documented object system. To see the difference use the following commands on each:

isa(ah, 'handle')
ishandle(ah)

The documented classes will return false for the second command.

4. MATLAB contains example code for subclassing handle graphics objects see uitab and uitabgroup.

5. axes is a built-in class so I don't believe you will be able to replace it with your own axes code directly. You will have to make a class like myaxes and create your own plotting routines to use it.

Good Luck,

Donn

Subject: Subclass MATLAB's graphics objects

From: Steven_Lord

Date: 16 Dec, 2010 18:13:27

Message: 4 of 5



"Donn Shull" <donn.shull.no_spam@aetoolbox.com> wrote in message
news:iedjh1$a92$1@fred.mathworks.com...
> "per isakson" <poi.nospam@bimDOTkthDOT.se> wrote in message
> <iac203$1t0$1@fred.mathworks.com>...
>> "R Wat" <rhino7890@aol.com> wrote in message
>> <iabun4$jij$1@fred.mathworks.com>...
>> > For my research, the format of my plots is very specific and I would
>> > like to set up some default plotting procedures which abide by the
>> > formatting I must follow. Basically I need to make some modifications
>> > to the default style of the figure axes produced by matlab (i.e.
>> > whenever MATLAB calls a plotting function such as plot, surf etc. I
>> > want to have my axes used instead of the default MATLAB ones). For some
>> > of the properties, I can just use the following command
>> >
>> > set(0,'Default...',value,...)
>> >
>> > but some properties that I need to the axes can't be set this way (I
>> > have to add some arrows and other annotations).

So add in your own value for the DefaultAxesCreateFcn.

http://www.mathworks.com/help/techdoc/ref/axes_props.html#CreateFcn

Or, since this would affect ALL axes that were created after you set this
property (including some for which it may not be appropriate, like GUI axes)
you could create your own _function_ that creates an axes and adds the
appropriate annotation and call that in your code instead of AXES.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Subclass MATLAB's graphics objects

From: R Wat

Date: 16 Dec, 2010 19:06:09

Message: 5 of 5

>
> So add in your own value for the DefaultAxesCreateFcn.
>
> http://www.mathworks.com/help/techdoc/ref/axes_props.html#CreateFcn
>
> Or, since this would affect ALL axes that were created after you set this
> property (including some for which it may not be appropriate, like GUI axes)
> you could create your own _function_ that creates an axes and adds the
> appropriate annotation and call that in your code instead of AXES.

The axes property DefualtAxesCreateFcn was what I was looking for. Thanks for the help.

Tags for this Thread

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.

Contact us