How can i specify which subplot that i want to plot on it?

41 ビュー (過去 30 日間)
Le Dung
Le Dung 2017 年 12 月 15 日
コメント済み: Image Analyst 2025 年 4 月 17 日
Hi everyone! Now, i want to draw an animated arrow (general is any object) and an animated line, each of them is plotted on each subplot. I used draw-delete method to create an animated arrow and use "addpoints" command to create an animated line. Of course, we need a for loop, and so on. You can see below code. But, i couldn't do what i want with this code. The animated arrow always drew on second subplot. Who can help me? P/s: My problem is "How can i specify which subplot that i want to plot on it?" Thank you so much. And, my code:
clear
clc
subplot(2,1,1);
axis([-1 24 -1.1 1.1]);
line([0 23],[0 0],'Color','r');
jumpstep=0.1;
subplot(2,1,2);
axis([0 240 -1.1 1.1]);
sodiem=linspace(0,23,231);
cvi=sin(sodiem);
higharrow=0.8;
ani=animatedline('Color','y');
for k=0:length(sodiem)-1
arr=arrow([jumpstep*k higharrow],[jumpstep*k 0],13,'EdgeColor','r','FaceColor','g');
addpoints(ani,sodiem(k+1),cvi(k+1))
drawnow
pause(0.01)
delete(arr);
end

採用された回答

KL
KL 2017 年 12 月 15 日
use axis handles,
ax1 = subplot(2,1,1);
something
ax2 = subplot(2,1,2);
something
now again go back to ax1
axes(ax1)
hold on
something more
  4 件のコメント
Costas
Costas 2025 年 4 月 16 日
the axes did not work for me. I used this instead
set(gcf,"CurrentAxes",axs(ax1));
Image Analyst
Image Analyst 2025 年 4 月 17 日
@Costas, not sure what axs is.
Anyway, to specify what axes to draw into you can simply call subplot again. You aren't limited to calling it just once and then storing the axes handle and messing around with that - too confusing. Simply call subplot again with the axes you want specified as the third argument:
% Switch current axes to subplot 1:
subplot(2,1,1);
% Now draw something in subplot 1.
hold on;
plot(rand(1,10));
% Switch current axes to subplot 2:
subplot(2,1,2);
% Now draw something in subplot 2.
hold on;
plot(rand(1,10));

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by