필터 지우기
필터 지우기

How to create two "axes" plots in the same GUI?

조회 수: 1 (최근 30일)
Abhay Aradhya
Abhay Aradhya 2017년 6월 8일
댓글: Adam 2017년 6월 9일
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

채택된 답변

Adam
Adam 2017년 6월 8일
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.
  댓글 수: 2
Abhay Aradhya
Abhay Aradhya 2017년 6월 9일
편집: Abhay Aradhya 2017년 6월 9일
Sorry my bad, the below is the exact code
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
I tried your suggestion as indicated in the code above but Matlab throws a "Invalid handle." error on the line marked by Plot3..!!
Is there a different syntax for "Plot3"?
Adam
Adam 2017년 6월 9일
What is that subplot call supposed to be doing? subplot creates axes, but you are creating your own axes so why use subplot after that? Either use subplot or create your own axes.
Again though with subplot, it returns a handle to the axes it creates. Store this and use it, in plot instructions and in hold, grid and any other instructions that you expect to be applied to a single axes.
You have six
hold on
instructions in that code, and that isn't counting the number of times the instructions inside the for loop get called. Just set
hold( ax, 'on' )
once. Throwing in more and more 'hold on' instructions and leaving them all in when they don't work just leads to overly messy code.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by