[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problems with a linked function
From: |
Markus Michael Rau |
Subject: |
Problems with a linked function |
Date: |
Wed, 20 Jun 2012 07:06:06 -0700 (PDT) |
I just wrote a linked function to calculate the integral between two points.
It should basically do the same as the following octave function:
function [bins] = ber_bins(f, reds)
binsmaxindex = length(reds) - 1;
for i = 1:binsmaxindex
x(1) = reds(i);
x(2) = reds(i + 1);
y(1) = f(i);
y(2) = f(i + 1);
bins(i) = trapz(x, y);
endfor
endfunction
My c++ quellcode reads as follows:
#include <octave/oct.h>
#include <octave/parse.h>
DEFUN_DLD(my_bins, argv, ,"Usage: Calculates the bins"){
octave_value_list retval;
octave_value_list listzw;
octave_value zwisch;
int nargin = argv.length();
if(nargin != 2){
print_usage();
}else{
ColumnVector f = argv(1).column_vector_value();
ColumnVector red = argv(0).column_vector_value();
ColumnVector x(2);
ColumnVector y(2);
octave_value_list listzw;
int binsmaxindex = f.length() - 1;
ColumnVector bins(binsmaxindex);
const double *redval = red.fortran_vec();
const double *fval = f.fortran_vec();
double *xval = x.fortran_vec();
double *yval = y.fortran_vec();
double *binsval = bins.fortran_vec();
for(int i = 0; i < binsmaxindex; ++i){
xval[0] = redval[i];
xval[1] = redval[i + 1];
yval[0] = fval[i];
yval[1] = fval[i + 1];
listzw(0) = octave_value(x);
listzw(1) = octave_value(y);
zwisch = feval("trapz",listzw, 1);
binsval[i] = zwisch.scalar_value();
}
retval.append(octave_value(bins));
return retval;
}}
I get the following error if i for example call the function:
test = my_bins([1;2], [1;4])
error: octave_base_value::double_value (): wrong type argument `list'
I just don't see the type list in the documentation
http://www.gnu.org/software/octave/doc/interpreter/Matrices-and-Arrays-in-Oct_002dFiles.html#Matrices-and-Arrays-in-Oct_002dFiles
How can I solve the problem?
Thanks for your support,
Markus
--
View this message in context:
http://octave.1599824.n4.nabble.com/Problems-with-a-linked-function-tp4630829.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Problems with a linked function,
Markus Michael Rau <=