Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Parent of Map Axes in Matlab GUI

I am programming a basic GUI in MATLAB that utilizes the mapping toolbox. The GUI will display a grayscale image and then plot discrete points over the data, all of this over the necessary map projection. It is important that I plot onto map axes (those created by the axesm command) rather than the vanilla cartesian space. I have no problem doing all this from the command line, but I cannot find a way to implement a GUI version and its driving me nuts.

The problem is that I need to specify the map axes as being the child of the parent figure. The normal axes has a property that can be set, doing something like:

axesHandle = axes('Parent', parentHandle, ...);

or

set(axesHandle, 'Parent', parentHandle);

However, there is no equivalent parent property for the map axes created by the axesm function, so I have no way to manipulate the axes within the figure. How can I do this?


Update: If I create a plot within the map axes in an empty figure, get(figureHandle, 'Children') returns the handle of the axesm object (thanks @slayton!), so the map axes object must be implicitly added to the children of the figure by MATLAB.

Should I be concerned that the map axes do not refer back to the parent figure, or should I just let it be? I wonder if this is a classic case of MATLAB forcing me to not comply with the standards the manual tells me to implement.

like image 325
lstyls Avatar asked Jan 01 '26 05:01

lstyls


1 Answers

From reading your question what I think you are trying to do is grab the handle of the axes object. This can be done as the axes is created using either axes or subplot

a = axes();
a = subplot(x,y,z);
% both return an handle to the newly created axes object

Additionally if the axes is created automagically by a function call like plot or image you can get the axes handle that too:

p = plot(1:10); %returns a handle to a line object
a = get(p,'Parent');

i = image(); %returns a handle to an image object
a = get(i, 'Parent');

Finally, neither of those two options is available you can always get the axes handle from its containing figure with:

a = get(figureHandle, 'Children');

Remember though that this will return a vector of axes handles if your figure contains more than one axes.

Finally when it comes time to draw draw your points to the axes that contains your map image you simply need to call:

line(xPoints, yPoints, 'linestyle', 'none', 'marker', '.', 'color', 'r', 'size', 15)

This will draw the vertices of the line using large red dots.

I'm not sure if this answers your question because the code you provided doesn't line up with the question you asked.

The code you provided looks like you are trying to move an axes from one figure to another. You can totally do this!

f = figure('Position', [100 100 100 100]);
a = axes('Parent', f);
pause
f2 = figure('Position', [250 100 100 100]);
set(a,'Parent', f2);
like image 200
slayton Avatar answered Jan 02 '26 18:01

slayton