octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fwd: Re: [OctDev] ndgrid]


From: Alexander Barth
Subject: [Fwd: Re: [OctDev] ndgrid]
Date: Tue, 23 May 2006 10:32:27 -0400
User-agent: Thunderbird 1.5.0.2 (X11/20060501)

Hi All,

Here is an implementation of the function ndgrid (a multi-dimensional extension of meshgrid) that you might want to include in octave.
Any comments?

Cheers,
Alex



-------- Original Message --------
Subject: Re: [OctDev] ndgrid
Date: Tue, 23 May 2006 16:10:23 +0200
From: David Bateman <address@hidden>
Reply-To: address@hidden
Organization: Motorola CRM
To: Alexander Barth <address@hidden>
CC: Octave Forge <address@hidden>
References: <address@hidden>


Alexander Barth wrote:

> Hi All,
>
> I wrote the function ndgrid (a multi-dimensional extension of
> meshgrid). In matlab, this function is located in "elmat". Where can I
> commit this function in octave-forge? Is main/general the appropriate
> place?
>
> Cheers,
> Alex
>
This is a core function of Matlab. At the moment I'm in the process of
cleaning out all of the matlab core functions that are in octave-forge
and feeding them to John. I'd therefore suggest that you don't submit
this to octave-forge at all, but rather send your implementation to
address@hidden for discussion, and when it is acceptable as a
core function I imagine John will commit it to octave's CVS..

Regards
David

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Octave-dev mailing list
address@hidden
https://lists.sourceforge.net/lists/listinfo/octave-dev


-- 
_______________________________________________________________

  Alexander Barth

  Ocean Circulation Group
  University of South Florida
  College of Marine Science
  140 Seventh Avenue South 
  St. Petersburg, Florida  33701
  USA

  Phone: +1-727-553-3508     FAX:   +1-727-553-1189

_______________________________________________________________
## Copyright (C) 2006, Alexander Barth
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, write to the Free
## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.

## -*- texinfo -*-
## @deftypefn {Function File} address@hidden, @var{y2}, ...,  @var{y}n]} = 
ndgrid (@var{x1}, @var{x2}, ..., @var{x}n)
## @deftypefnx {Function File} address@hidden, @var{y2}, ...,  @var{y}n]} = 
ndgrid (@var{x})
## Given n vectors @var{x1}, ... @var{x}n, ndgrid returns n arrays of dimension 
n. 
## The elements of the ith output argument contains the elements of the vector 
## @var{x}i repeated over all dimensions different from the ith dimension.
## Calling ndgrid with only one input argument @var{x} is equivalent of calling 
ndgrid with 
## all n input arguments equal to @var{x}:
##
## address@hidden, @var{y2}, ...,  @var{y}n] = ndgrid (@var{x}, ..., @var{x})
## @seealso{meshgrid}
## @end deftypefn

## Author: Alexander Barth <address@hidden>

function varargout = ndgrid(varargin)

if (nargin == 1)
  n = max([nargout 2]);  
  ## If only one input argument is given, repeat it n-times
  varargin{1:n} = varargin{1};
elseif (nargin >= nargout)
  n = max([nargin 2]);  
else
  error ("ndgrid: wrong number of input arguments");
endif


## Determine the size of the output arguments
                                
shape = zeros(1,n);

for i=1:n
  if (~isvector(varargin{i}))
    error ("ndgrid: arguments must be vectors");
  endif

  shape(i) = length(varargin{i});
endfor

for i=1:n

  ## size for reshape
  r = ones(1,n);
  r(i) = shape(i);

  ## size for repmat
  s = shape;
  s(i) = 1;

  varargout{i} = repmat(reshape(varargin{i},r) ,s);
endfor



endfunction

reply via email to

[Prev in Thread] Current Thread [Next in Thread]