MATLAB: How to create two “axes” plots in the same GUI

3d plotsaxesguidehandlesMATLABmatlab guisubplot

customUserInterface = figure('Name','Solution selector window');
ax = axes('Parent',customUserInterface,'Position',[.1 .5 .375 .4]);
subplot(ceil(sqrt(size(sectors_all,1))),ceil(sqrt(size(sectors_all,1))),p, 'Position',[.1 .5 .375 .4]);
hold on
for m=1:numOfAP
plot3(ax,Data(m).traj(:,1),Data(m).traj(:,2),Data(m).traj(:,3),'g','LineWidth',2)
hold on
grid on
end
hold on
ab = axes('Parent',customUserInterface,'Position',[.525 .5 .375 .4]);
subplot(ceil(sqrt(size(sectors_all,1))),ceil(sqrt(size(sectors_all,1))),p, 'Position',[.525 .5 .375 .4]);
hold on
for m=1:numOfAP
plot3(ab,Data(m).traj(:,1),Data(m).traj(:,2),Data(m).traj(:,3),'g','LineWidth',2)
hold on
grid on
end
hold on
In this case it only plots the 2nd axes..!!
Please suggest me a better way to do this. Thanks in advance

Best Answer

You haven't shown any plotting code so I can only guess at what you are doing which is a bit silly if you are trying to get an answer to a question! I suspect you are just doing what too many people do and something to the effect of just
plot( xData, yData );
If you look at the documentation:
doc plot
you will see
plot(ax,___)
as an option. This syntax works exactly as your (presumed) current syntax, but you give it the axes handle onto which to plot as the first argument. This is far better than just relying on whatever the current axes happens to be which is what the first syntax does.