How can I get the exact plots mentioned in the figure below

2 Ansichten (letzte 30 Tage)
Pranjal Bhatia
Pranjal Bhatia am 7 Okt. 2020
Kommentiert: Pranjal Bhatia am 8 Okt. 2020
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 Kommentare
Mathieu NOE
Mathieu NOE am 7 Okt. 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');
Pranjal Bhatia
Pranjal Bhatia am 7 Okt. 2020
Bearbeitet: Pranjal Bhatia am 7 Okt. 2020
I want to plot all the obstacles and agents together. Something quite similar in the figure. But I want it to be a live view, that is observe how ode45 is updating the position in real time. Also the number of agents are 6 so there are 6 columns in total for each agent and number of rows are dependent on ode45

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Mohammad Sami
Mohammad Sami am 7 Okt. 2020
Bearbeitet: Mohammad Sami am 7 Okt. 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 Kommentare
Mohammad Sami
Mohammad Sami am 8 Okt. 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
Pranjal Bhatia
Pranjal Bhatia am 8 Okt. 2020
Thanks for the help!
What if X is something like (12,64)?
Like its for 6 agents with one row for x axis and one row for y axis.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by