How can I get the exact plots mentioned in the figure below
4 views (last 30 days)
Show older comments
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.

2 Comments
Mathieu NOE
on 7 Oct 2020
hello
do you mean to plot all obstacles and agents in one plot , or do you split the data in multiple plots.
if you need a simple plot example see below. there are plenty of possibilities to make a nicer plot - see File Exchange
% obstacles
N = 50;
obstacles = [10*randn(1,10*N); 10*randn(1,10*N)];% example
% agents : size 2 X 64
agents = 3*[randn(2,64)]; % example
% basic plot
figure(1)
plot(obstacles(1,:),obstacles(2,:),'*b',agents(1,:),agents(2,:),'+r');grid on
title('Basic plot');
xlabel(' x coordinates');
ylabel(' y coordinates');
Answers (1)
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
3 Comments
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
See Also
Categories
Find more on Axes Appearance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!