MATLAB简单点图绘制。

3
在 while 循环中,我需要绘制两个实体的位置 (x,y)。也就是说,我只需要生成一个包含两个点的图表。我需要将图表缩放到特定的最大 x 值和 y 值。另外一个要求是其中一个点需要有三个同心圆环并且每个环的半径都已知。此外,这一切都需要在循环中发生,因此我希望只有一个绘图窗口打开,而不会出现一堆窗口打开(对应每次循环迭代)。
基本上,这是我正试图实现的伪代码:
-> Open new plot window, with a given x and y axis
while (running) {
  -> Clear the plot, so figure is nice and clean
  -> Plot the two points
  -> Plot the three circles around point A
}

我在 MATLAB 的文档中找到了几个项目,但似乎没有单个绘图函数可以实现我想要的功能,或者我不小心创建了只有部分数据的多个绘图(即一个绘图具有点,而另一个绘图具有圆圈)。

3个回答

3
这里是你可以在while循环中使用的示例代码。
x0=1; y0=4; 
x1=2; y1=3;  % the x-y points
r=[1 2 3]; % 3 radii of concentrating rings
ang=0:0.01:2*pi; 
xc=cos(ang)'*r;
yc=sin(ang)'*r;

plot(x0,y0,'.',x1,y1,'.'); % plot the point A
hold on
plot(x1+xc,y1+yc); % plot the 3 circles

% set the limits of the plots (though Matlab does it for you already)
xlim([min([x0 x1])-max(r) max([x0 x1])+max(r)]);
ylim([min([y0 y1])-max(r) max([y0 y1])+max(r)]);

hold off

你可以很容易地在循环中完成这项工作,请阅读Matlab的文档以了解如何执行此操作。

2

尝试像这样:

r = [0.25 0.125 0.0625];
d = (1:360) / 180 * pi;
xy_circle = [cos(d)' sin(d)'];
xy_circle_1 = r(1) * xy_circle;
xy_circle_2 = r(2) * xy_circle;
xy_circle_3 = r(3) * xy_circle;

h_plot = plot(0, 0, '.k');
hold on
h_circle_1 = plot(xy_circle_1(:, 1), xy_circle_1(:, 2), '-b');
h_circle_2 = plot(xy_circle_2(:, 1), xy_circle_2(:, 2), '-r');
h_circle_3 = plot(xy_circle_3(:, 1), xy_circle_3(:, 2), '-g');
axis equal

for hh = 1:100
  xy = rand(2, 2) / 4 + 0.375;
  xlim = [0 1];
  ylim = [0 1];
  set(h_plot, 'XData', xy(:, 1));
  set(h_plot, 'YData', xy(:, 2));

  set(gca, 'XLim', xlim)
  set(gca, 'YLim', ylim)

  set(h_circle_1, 'XData', xy_circle_1(:, 1) + xy(1, 1));
  set(h_circle_1, 'YData', xy_circle_1(:, 2) + xy(1, 2));
  set(h_circle_2, 'XData', xy_circle_2(:, 1) + xy(1, 1));
  set(h_circle_2, 'YData', xy_circle_2(:, 2) + xy(1, 2));
  set(h_circle_3, 'XData', xy_circle_3(:, 1) + xy(1, 1));
  set(h_circle_3, 'YData', xy_circle_3(:, 2) + xy(1, 2));

  pause(1)
end

您可以根据需要更改参数。


0
你可以使用以下函数。
figure;        %creates a figure
hold on;       %overlays points and circles
clf;           %clear the figure

并使用不同尺寸的点和圆,两种标记(.o

plot(x,y, 'b.', 'MarkerSize', 4);
plot(x,y, 'ro', 'MarkerSize', 10);
plot(x,y, 'go', 'MarkerSize', 14);
plot(x,y, 'bo', 'MarkerSize', 18);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接