help-octave
[Top][All Lists]
Advanced

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

Re: about logarithm in .cc files


From: Jaroslav Hajek
Subject: Re: about logarithm in .cc files
Date: Wed, 5 Jan 2011 21:54:41 +0100

2011/1/5 Andy Buckle <address@hidden>:
> On Wed, Jan 5, 2011 at 3:21 PM, 时刻 <address@hidden> wrote:
>>
>> Hello all,
>>  I am working with Oct-Files, and  encountering a problem, that is, how to 
>> write logarithm in .cc files. In .m files it is simple, i.e. log(x), here I 
>> set x to be a matrix. So how to do it in .cc files?
>> Thanks
>>
>> Best regards,
>
> The trick seems to be to make it into an octave_value first.
>
> #include "octave/oct.h"
>
> DEFUN_DLD (log, args, nargout,"") {
>  octave_value_list retval;
>
>  const int rows=3, cols=4;
>
>  dim_vector dv(rows,cols);
>  NDArray arr(dv);
>  double * pix_p=(double *)arr.fortran_vec();
>
>  for (uint32_t i=0; i<rows*cols ;i++) {
>    pix_p[i] = i;
>  }
>
>  octave_value arrval(arr);
>
>  return arrval.log();
> }
>


You can do it for NDArray directly:
arr.map<double>(log);

but it won't give you the automatic real->complex promotion if there
are negative elements.


reply via email to

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