lstyls
lstyls

Reputation: 173

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.

Upvotes: 3

Views: 6859

Answers (2)

lstyls
lstyls

Reputation: 173

After much trial and error and reading of documentation, I have found that there is no way to explicitly specify the parent of the map axes. Instead, they are implicitly added on top of the current axes. In the instance that no axes exist in the current figure, calling axesm creates an axes object and then places the axesm object inside. When you take this route, you have to grab the axes object handle by calling gca:

mapAxesHandle = axesm(...);
axesHandle = gca(...);

This makes it frustrating to use the mapping toolbox when writing a GUI from scratch, but that's the way Mathworks makes it happen. Thanks to @slayton for useful info. I'd upvote but my reputation is <15 :(

Upvotes: 0

slayton
slayton

Reputation: 20309

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);

Upvotes: 2

Related Questions