【问题标题】:How to plot 2 figures in a loop in MATLAB?如何在 MATLAB 中循环绘制 2 个图形?
【发布时间】:2022-11-16 14:48:52
【问题描述】:

我的问题是,我想要一个图中的两个图,其中只有一个图保持其价值。 这是代码:

%% 1. Parameters

xmin =    0;    % minimal distance
xmax =  200;    % maximal distance
ymin = -100;    % minimal height
ymax =  100;    % maximal height

% d. Parameters for gravitation and simulation time
g       = -9;% m/s^2
dt      = 0.01; % time resolution for simulation

%% 2. Simulation for throwing
% Initial coordinates
y = 0;
x = 0;
% Initial time
t = 0;          % time
% Initial velocity

v0=35;

% Initiate plot
figure(1)
   H = plot(x,y,'.','MarkerSize', 20);
   xlim([xmin xmax])
   ylim([ymin ymax])
   xlabel('Distance [m]')
   ylabel('Height [m]')
   grid on

% SIMULATION
while((x<=xmax) && (x>=xmin) && (y>=ymin) && (y<=ymax))
   t   = t  + dt;      % time change
   v0  = v0 + g*dt;    % change of the vy
   
   x   = x  + dt*v0;   % new x position

   set(H,'Xdata',x,'Ydata',y); % Move object
   drawnow;                    % Update graphics
end

结果图是这样的(带有更新标记):

我也想绘制位移,所以新结果看起来像这样(使用不同的标记):

【问题讨论】:

    标签: matlab plot


    【解决方案1】:

    你试过只使用hold on吗?获取另一个句柄,然后使用与第一个图相同的方式设置。

    % Initiate plot
    figure(1)
    H = plot(x,y,'.','MarkerSize', 20);
    hold on;
    H2 = plot(x2, y2) ;
    

    【讨论】:

      猜你喜欢
      • 2016-02-09
      • 2016-09-29
      • 2019-06-30
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多