MATLAB Answers

plot multiple rectangles/circles in the same frame, hold on

23 views (last 30 days)
Ansgar Elles
Ansgar Elles on 18 Feb 2021
Answered: KSSV on 18 Feb 2021
Hi I want to plot any desired number of circles in one plot for a billiard game. Creating each rectangle for itself isnt so handy because I would like to plot theoratically an infinite number of balls.
Thats why I wondered if its possible to plot the same object/rectangle at different positions at the same time. I tried using hold on. But it shows still only one ball.
hold on
for k1 = 1:length(t) %t = timestep
for k2 = 1:4:num_variables %this loop iteration should pick and plot one ball, ...
% which then needs to be held until all balls are plotted and a new timestep can be started
%k2 refers to x-value column, k2+2 refers to y-value column
set(redball,'Position',[y_total(k1,k2)-r, y_total(k1,k2+2)-r, 2*r, 2*r]);
end
How would you solve this?
Thanks in advance!!

Answers (1)

KSSV
KSSV on 18 Feb 2021
To plot them you can specify the centers and use markers, increase the size of markers. Have a look on plot.

Community Treasure Hunt

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

Start Hunting!

Translated by