Charlie
Charlie

Reputation: 252

Holding multiple axes' plots in Matlab GUI:

I'm currently developing a GUI (programatically. No GUIDE has been used) for a project and I need to place 11 axes on the same GUI. I'm using the axes command to get the handles of the 11 controls:

h.AXES_ALL(1)=axes('parent',h.fig,'position',[L1 T W H]);
h.AXES_ALL(2)=axes('parent',h.fig,'position',[L2 T W H]);
h.AXES_ALL(3)=axes('parent',h.fig,'position',[L3 T W H]);
...

They all have the same dimensions and I'm using the for instruction to plot the data:

for i=1:11
           set(h.PLOT(i),'parent',h.AXES_ALL(i),'XData',x_data,'YData',y_data);            
end

But the problem is that the last plot (the 11th) is the one that is shown on the axes control (the 11th) and all the other axes are empty. My objective is to plot 11 curves on 11 different axes controls. They aren't located in the same position, just for the record.

THanks in advance!

Charlie

Upvotes: 0

Views: 2776

Answers (1)

chappjc
chappjc

Reputation: 30579

You said in your comment that you start with a single axes handle:

ha = axes;

And you try to create two plots with the same parent axes, but it does not work as you intended:

>> h.PLOT(1:2) = plot(ha,0,0)
h.PLOT =
  195.0035  195.0035

That just replicated the same plot series handle. So, when you go to set the plot data and parent axes for each plot, you are just moving the plot from axes to axes, updating the data while you go.

Use the plot command in a loop, using the appropriate axes handle for each plot:

for ip=1:11,
    h.PLOT_ALL(ip) = plot(h.AXES_ALL(ip),...);
end

Then when you update the plot's XData and YData as you want to do, you do not have to change the parent axes.

Upvotes: 2

Related Questions