LINUX.ORG.RU

Octave опять


0

0

Не пойму, как работает meshgrid

Что будет в zz, если:

x = [-3:3]

[xx,yy,zz] = meshgrid (x,x,x)

Если у кого нет, код такой:

function [xx, yy, zz] = meshgrid (x, y, z)

  if (nargin == 0 || nargin > 3)
    print_usage ();
  endif

  if (nargin < 2)
    y = x;
  endif

  ## Use repmat to ensure that the result values have the same type as
  ## the arguments.

  if (nargout < 3)
    if (isvector (x) && isvector (y))
      xx = repmat (x(:).', length (y), 1);
      yy = repmat (y(:), 1, length (x));
    else
      error ("meshgrid: arguments must be vectors");
    endif
  else
    if (nargin < 3)
      z = y;
    endif
    if (isvector (x) && isvector (y) && isvector (z))
       lenx = length (x);
       leny = length (y);
       lenz = length (z);
       xx = repmat (repmat (x(:).', leny, 1), [1, 1, lenz]);
       yy = repmat (repmat (y(:), 1, lenx), [1, 1, lenz]);
       zz = reshape (repmat (z(:).', lenx*leny, 1)(:), leny, lenx, lenz);
    else
      error ("meshgrid: arguments must be vectors");
    endif
  endif

endfunction
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.