help-octave
[Top][All Lists]
Advanced

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

Re: complex arrays in octfiles


From: c.
Subject: Re: complex arrays in octfiles
Date: Wed, 29 Jun 2011 15:35:28 +0200

On 29 Jun 2011, at 15:03, pantxo diribarne wrote:

> Hello list,
> 
> I would like to write an octfile extention that takes mainly vectors as input 
> arguments and returns a complex 3 dimensiosional array, but I could'nt figure 
> out how to populate/access  CNDArray elements.
> 
> Are there available examples?
> 
> Pantxo 

ComplexNDArray should essentially an Array<std::complex<double> > so you should 
find most of the information you need here:

http://octave.sourceforge.net/doxygen/html/class_array.html
http://octave.sourceforge.net/doxygen/html/class_complex_n_d_array.html

Here is an example of how to build A ComplexNDArray:

#include <octave/oct.h>

DEFUN_DLD (pippo, args, , "test return statement")
{

  dim_vector dims;
  dims.resize (3);
  dims(2) = 4;
  dims(1) = 3;
  dims(0) = 2;


  ComplexNDArray a (dims, std::complex<double> (0.0, 0.0));
  // or 
  //Array<std::complex<double> > a (dims, std::complex<double> (0.0, 0.0));
  for (octave_idx_type i = 0; i < dims(0); i++)
    for (octave_idx_type j = 0; j < dims(1); j++)
      for (octave_idx_type k = 0; k < dims(2); k++)
        a (i, j, k) = std::complex<double> (i, j + k);

  return octave_value (a);

}

HTH,
c.

reply via email to

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