How to select specific figure and specific axes for plot?

130 views (last 30 days)
Hi,
i have a code running where you can open a figure (here: animation.fig), which has been pre-created with guide.
this figure contains static-text and 2 axes.
How can i select in which figure and in which axes of this figure i want to draw my plot??
I've been searching for a lot of time, but can't get it working.
I tried of course
figure(animation); % open figure and set to active
ax = findobj(animation, 'Type', 'Axes'); % get all axes in this figure (works! Here: axes2 and axes3)
axes(handles.axes2); <-- doesn't work: "Unrecognized field name "axes2"
Please help :-)

Answers (2)

Heiko
Heiko on 20 Mar 2023
Hi Antoni,
thank you so much!!
What i think i have learned:
animation=openfig('animation.fig'); % not only just opening but defining an 'object' being the actual parent
NAxes=animation.Children; % here i learnend about correct use of children/ parent settings
a1=NAxes(1); % within NAxes() are all 'children' of the current parent figure. Might be static text, axes...
plot(YourData,'Parent',a1) % Plot/ write data in current parent and in children a1 as declared the line above
Heiko :)

Antoni Garcia-Herreros
Antoni Garcia-Herreros on 17 Mar 2023
Hello Heiko,
You can take a look here.
You could try something like this:
% Let's say your figure has been saves as a .fig file
animation=openfig('animation.fig');
NAxes=animation.Children;
a1=NAxes(1); % Chose your depending on where you want to plot your data (1 or 2)
hold(a1,'on') % If there is data already in the plot you may want to hold it
plot(YourData,'Parent',a1) % Plot data on ax1
I hope this helps!

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!