0

我已经运行了一个 MATLAB 程序将近六个小时,但它仍然不完整。它循环通过三个while循环(外部两个循环为n = 855,内部循环为n = 500)。花了这么长时间,这是否令人惊讶?有什么办法可以提高速度吗?我包括下面的代码,以及下面的变量数据类型。

  while i < (numAtoms + 1)
      pointAccessible = ones(numPoints,1);
      j = 1;
      while j <(numAtoms + 1)
          if (i ~= j)
              k=1;
              while k < (numPoints + 1)
                  if (pointAccessible(k) == 1)
                      sphereCoord = [cell2mat(atomX(i)) + p + sphereX(k), cell2mat(atomY(i)) + p + sphereY(k), cell2mat(atomZ(i)) + p + sphereZ(k)];
                      neighborCoord = [cell2mat(atomX(j)), cell2mat(atomY(j)), cell2mat(atomZ(j))];
                      coords(1,:) = [sphereCoord];
                      coords(2,:) = [neighborCoord];
                      if (pdist(coords) < (atomRadius(j) + p))
                          pointAccessible(k)=0;
                      end
                  end
                  k = k + 1;
              end
          end
          j = j+1;
      end
      remainingPoints(i) = sum(pointAccessible);
      i = i +1;
  end

变量数据类型:

  numAtoms = 855
  numPoints = 500
  p = 1.4
  atomRadius = <855 * 1 double>
  pointAccessible = <500 * 1 double>
  atomX, atomY, atomZ = <1 * 855 cell>
  sphereX, sphereY, sphereZ = <500 * 1 double>
  remainingPoints = <855 * 1 double>
4

0 回答 0