【问题标题】:Plot even columns against odd columns of an array in MATLAB在 MATLAB 中针对数组的奇数列绘制偶数列
【发布时间】:2018-06-24 07:12:04
【问题描述】:

我在 MATLAB 中有一个大型数组,指定了许多粒子在 2D 中的位置。每行对应一个粒子。第 2n-1 和第 2n 列给出粒子在给定时间的 x 和 y 坐标,第 2n+1,2n+2 列给出下一个时间间隔的坐标。我正在尝试绘制所有这些点,将它们连接起来,以便在一个图上显示粒子的轨迹,但我不确定在这种情况下 plot 命令的参数应该是什么。

【问题讨论】:

    标签: matlab matlab-figure


    【解决方案1】:

    试试下面的代码。前六行创建了大型阵列的微型版本。如果我看错了它的安排,请告诉我。

    %      x,y   x,y   x,y   x,y
    p1 = [ 1,2, -1,3, -2,6, -3,7]; % positions of particle 1
    p2 = [ 2,3,  2,4,  3,6   3,8]; % positions of particle 2
    p3 = [-1,-3, 0,-1, 1,0,  2,2]; % positions of particle 3
    
    ps = [p1;p2; p3]; % "large array"
    
    px = ps(:,1:2:end)'; % particles' x-positions
    py = ps(:,2:2:end)'; % particles' y-positions
    
    plot(px,py) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-06
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      • 2014-09-20
      • 1970-01-01
      相关资源
      最近更新 更多