You have to obtain the handle of the axes you want to draw in. You can get it either by e.g. findobj, when you define a unique Tag property for the concerned axes.
figure;
axes('Tag', 'IWantToDrawHere');
Code of the other GUI:
figure;
uicontrol('Style', 'PushButton', 'Callback', @buttonCallback);
function buttonCallback(ButtonH, EventData)
AxesH = findobj('Tag', 'IWantToDrawHere');
if length(AxesH) ~= 1
warning('Cannot find my axes?!');
return;
end
plot(1:10, rand(1, 10), 'Parent', AxesH);
A drawback of this method is the run-time: If you have many open figures with a lot of objects, searching all of them to find the tag is not fast. So it would be better to store the axes handle in the UserData or ApplicationData of the figure and search it there.
1 Comment
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/252521-how-to-define-an-axis-in-other-figure-to-plot-in-it#comment_320376
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/252521-how-to-define-an-axis-in-other-figure-to-plot-in-it#comment_320376
Sign in to comment.