2 views (last 30 days)

Hello, I am trying to implement something and for the final plot I need something like the one in the attachment below.

The blue dots represent randomly initialized Obstacles so something like

O = [10*randn(1,10*N); 10*randn(1,10*N)];

Where N is the number of obstacles. So N can be like 50 or something. The red dots represent moving agents for which I have some predefined equations and its being run through ode45 and I am getting a matrix of 2 X 64, where each row 1 correpsonds to x position and row 2 to Y position.

Mohammad Sami
on 7 Oct 2020

Edited: Mohammad Sami
on 7 Oct 2020

You can start here

N = 50;

O = 10*randn(2,10*N);

tiledlayout(2,5);

for i = 1:10

ax = nexttile;

X = 10*randn(2,64); % generate some X values

plot(ax,O(1,:),O(2,:),'bd',X(1,:),X(2,:),'r*','MarkerFaceColor','b','MarkerSize',3);

grid on;

end

Mohammad Sami
on 8 Oct 2020

Can replace tiledlayout with subplot

N = 50;

O = 10*randn(2,10*N);

for i = 1:10

ax = subplot(2,5,i);

X = 10*randn(2,64); % generate some X values

plot(ax,O(1,:),O(2,:),'bd',X(1,:),X(2,:),'r*','MarkerFaceColor','b','MarkerSize',3);

grid on;

end

For live update you can do something like this

N = 50;

O = 10*randn(2,10*N);

X = 10*randn(2,64); % generate some X values

p = plot(O(1,:),O(2,:),'bd',X(1,:),X(2,:),'r*','MarkerFaceColor','b','MarkerSize',3);

grid on;

% update the plot

for i = 1:10

X = 10*randn(2,64); % generate some X values

set(p(2),'XData',X(1,:),'YData',X(2,:));

drawnow;

pause(1); % pause can be removed

end

Opportunities for recent engineering grads.

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

Start Hunting!
## 2 Comments

## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/607031-how-can-i-get-the-exact-plots-mentioned-in-the-figure-below#comment_1042256

⋮## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/607031-how-can-i-get-the-exact-plots-mentioned-in-the-figure-below#comment_1042256

## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/607031-how-can-i-get-the-exact-plots-mentioned-in-the-figure-below#comment_1042506

⋮## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/607031-how-can-i-get-the-exact-plots-mentioned-in-the-figure-below#comment_1042506

Sign in to comment.