From: paul <ppr...@wi...> - 2005-07-31 16:41:27
|
Michael Hearne wrote: >I'm getting a segmentation fault when trying to assign a Cell array to an >Octave_map object, and I don't quite understand why. What is the appropriate >way to insert a cell array into an Octave_map? Below is some sample code and >the results I get. > >Thanks in advance, > >Mike > >------------------------------------------------------------- >#include <oct.h> >#include <ov-cell.h> >#include <ov-struct.h> >#include <string> > >using namespace std; > >DEFUN_DLD(testoctave, args, nargout, > "Play around with stuff."){ > > Octave_map tstruct; > octave_cell cellnames; > message("1","Before cell assignment"); > cellnames.assign(octave_value(1),octave_value("fred")); > cellnames.assign(octave_value(2),octave_value("wilma")); > message("2","Before struct 'couple' assignment"); > tstruct.assign("couple","Flintstones"); > message("3","Before struct 'names' assignment"); > tstruct.assign("names",cellnames); > message("4","After struct 'names' assignment"); > octave_value_list retval; > return retval; >} >------------------------------------------------------------- > > Michael, I got your program to work doing the following: #include <oct.h> #include <ov-cell.h> #include <ov-struct.h> #include <string> using namespace std; DEFUN_DLD(test2, args, nargout, "Play around with stuff."){ Octave_map tstruct; Cell cellnames(dim_vector(1,2)); message("1","Before cell assignment"); cellnames(0)=string("fred"); cellnames(1)=string("wilma"); message("2","Before struct 'couple' assignment"); tstruct.assign("couple","Flintstones"); message("3","Before struct 'names' assignment"); tstruct.assign("names",octave_value(cellnames)); message("4","After struct 'names' assignment"); octave_value_list retval; retval.append(tstruct); return retval; } As always with writing .oct programs, I'm not sure what made it work. I've never had much luck using octave_cell instead of Cell, and one of my gripes is that there are no comments in the headers as to what these things are intended for. Paul Probert |