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

조회 수: 2 (최근 30일)
Pranjal Bhatia
Pranjal Bhatia 2020년 10월 7일
댓글: Pranjal Bhatia 2020년 10월 8일
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
Mathieu NOE
Mathieu NOE 2020년 10월 7일
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 2020년 10월 7일
편집: Pranjal Bhatia 2020년 10월 7일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Mohammad Sami
Mohammad Sami 2020년 10월 7일
편집: Mohammad Sami 2020년 10월 7일
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
Mohammad Sami
Mohammad Sami 2020년 10월 8일
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 2020년 10월 8일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by