フィルターのクリア

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 Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by