フィルターのクリア

How to add 3th moving ball

3 ビュー (過去 30 日間)
dmfwlansejr
dmfwlansejr 2021 年 9 月 10 日
回答済み: Rik 2021 年 9 月 10 日
2 Ball is moving
I want to add 3th moving ball (start position (0,1))
How to is it?
Following is My Code :(For operate, Copy & Paste)
x1_st=0;y1_st=0.5;
x2_st=0;y2_st=1.5;
%plot
h_fg=figure;
h_ax=axes(h_fg);
h_p1=plot(h_ax,x1_st,y1_st,'b.','MarkerSize',40); hold(h_ax,'on');
h_p2=plot(h_ax,x2_st,y2_st,'r.','MarkerSize',40); hold(h_ax,'on');
% change Properties
set(h_ax,'XLim',[-5 5]);
set(h_ax,'YLim',[0 5]);
h_ax.YLim=[0 2];
h_ax.XLim=[-5 5];
% for loop
dx=[1:0.1:5, -5:0.1:0];
for ii=1:length(dx)
x1_new=x1_st+dx(ii);
x2_new=x2_st-dx(ii);
set(h_p1,'XData',x1_new);
set(h_p2,'XData',x2_new);
pause(0.02);
end

回答 (1 件)

Rik
Rik 2021 年 9 月 10 日
If you replace numbered variables with arrays you can use simple loops with indexing. With your current setup you will have to copy and paste every line of code referring to a ball.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by