plot3的积点保持matlab [英] plot hold for plot3 matlab

查看:105
本文介绍了plot3的积点保持matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个类似的问题,给出了答案.我的问题与该问题相同,除了我有2个循环而不是那里所示的一个.不过,该解决方案似乎对我不起作用.

There is a similar question, to which the answer was given. My question is the same as this one, except, I have 2 loops instead of one as showed there. Still, the solution does't seem to work for me.

问题:如何在何时保留图在matlab中使用plot3?

在这里,有一个单循环广告,该解决方案似乎可以正常工作.以下是我的代码:

Here, there is a single loop ad the solution seems to work fine. The following is my code :

  figure(1)
  for i = 1:n
      for j = 1:m
         if(condition)
              %some calculations to get X
              x = X(1,:);
              y = X(2,:);
              z = X(3,:);
              plot3(x,y,z,'.');
              view(3);
              hold on;
         end
      end
      hold on;
   end

在这里,使用"j"对内循环进行所有迭代之后,将获得正确的图,但是一旦转到外循环,则图将刷新并重新开始.如何维护两个循环的plot3?我在外部循环中再次使用了保持,但是它似乎仍然不起作用.谁能告诉我如何保持2个循环的绘图?预先感谢.

Here, after all iterations of the inner loop using 'j', am getting a proper plot, but once it goes to the outer loop, the plot refreshes and starts again. How can I maintain the plot3 for both the loops? I have used hold on again in the outer loop, but it still doesn't seem to work. Can anyone tell me how I can maintain the plot for 2 loops.? Thanks in advance.

推荐答案

我认为您的代码应该可以正常工作.但是,我将进行一些更改,这将对您遇到的任何问题有所帮助:

I think that your code should work as is. However, a few changes I would make, which should help whatever problem that you are having:

  1. hold on仅需要调用一次.
  2. view(3)也仅需要调用一次(实际上根本不需要将数据绘制出来,只是有助于可视化).
  3. 执行复杂的绘图时,通常需要指定要显式绘图的轴.否则,绘图将转到当前"轴,可以通过某些操作更改该轴. (取决于您在计算中的工作.)
  4. 当看起来没有将数据添加到绘图中时,一个常见的问题是轴缩放.您可以使用axis tight在缩放轴限制时获得不错的第一手猜测.
  1. hold on only needs to be called once.
  2. view(3) also only needs to be called once (actually is not needed at all to get the data plotted, just helps with the visualization).
  3. When I'm performing complex plotting, I usually need to specify the axis to plot on explicitly. Otherwise the plot goes to the "current" axis, which can be changed by some operations. (Depends what you are doing in your calculations.)
  4. A common problem when it looks like data is not being added to a plot is axis scaling. You can use axis tight for a decent first guess at scaling the axis limits.

将其放在一起,尝试一下,看看会发生什么:

Putting this together, try this, and see what happens:

%Set up figure to catch plots
figure(1);
hAxis = gca;  %This will create an axis in the figure, and return its handle
hold on;      %You can also use hold(hAxis,'on') if you are really paranoid about which axis is catching your commands

%Perform plots
for i = 1:n
    for j = 1:m
       if (condition)
            %some calculations to get X
            x = X(1,:);
            y = X(2,:);
            z = X(3,:);
            plot3(hAxis,x,y,z,'.');
       end
    end
 end

 %Adjust view etc (experiment here after the data is plotted)
 view(3)
 axis tight

这篇关于plot3的积点保持matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆