Question

How does one sort an array in a written dynamically linked function for Octave written c++?

A hypothesized example :

#include <octaveoct.h>
#include <octave_sort_file?.h>
DEFUN_DLD (func_mysort, args, ,"sort an array")
  {
    octave_value o0_retval;
    Columnvector v1_vector = args(0).vector_value() ;
    octave_sort(v1_vector) ;
    o0_retval = v1_vector ;
    return o0_retval ;
}
Was it helpful?

Solution

It's actually easier that it seems, you only have to use the sort() method. Take a look at Octave's doxygen documentation for ColumnVector:

#include <octave/oct.h>

DEFUN_DLD (foo, args, , "sort an array")
{
  ColumnVector unsorted = args(0).vector_value ();
  ColumnVector sorted = unsorted.sort ();
  return octave_value (sorted);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top