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

1 回表示 (過去 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 Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by