help-octave
[Top][All Lists]
Advanced

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

Passing big data arrays to oct-files


From: Reza Housseini
Subject: Passing big data arrays to oct-files
Date: Tue, 25 Sep 2012 17:09:24 +0200

Hello list

I want to pass a Matrix from Octave to my C++ script via the oct API.
My question is now, how can I get an Matrix class into an
vector<valarray<float> > class? Is there a way to achieve this without
copying every element? Here a small example:

tr1::shared_ptr<vector<valarray<float> > > Matrix2VectorValarray(Matrix V);

DEFUN_DLD(sievedeck, args, nargout, "No Help String Yet") {
  octave_value_list retval;
  int nargin = args.length();
  if (nargin != 1) print_usage();
  else {
    tr1::shared_ptr<vector<valarray<float> > > material = Matrix2VectorValarray(
      args(0).matrix_value());
  }
  return retval;
}

tr1::shared_ptr<vector<valarray<float> > > Matrix2VectorValarray(Matrix V) {
  dim_vector size = V.dims();
  tr1::shared_ptr<vector<valarray<float> > > R(new
vector<valarray<float> > (size(1)));
  for (int colIndex = 0; colIndex < size(1); colIndex++) {
    valarray<float> colVector(size(0));
    for (int rowIndex = 0; rowIndex < size(0); rowIndex++) {
      colVector[rowIndex] = V(rowIndex, colIndex);
    }
    (*R)[colIndex] = colVector;
  }
  return R;
}

Thanks for your help,
Reza


reply via email to

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