From help-octave-request at bevo dot che dot wisc dot edu Thu Feb 15 18:18:37 2001 Subject: Re: extract from cell? From: Paul Kienzle To: Daniel Heiserer Cc: "help-octave at bevo dot che dot wisc dot edu" Date: Thu, 15 Feb 2001 17:20:56 +0000 You could use the following untested function based on nth from ov-list.cc: - Paul DEFUN (cellget, args, , "-*- texinfo -*-\n\ at deftypefn {Built-in Function} {} nth (@var{cellget}, @var{i}, @var{j})\n\ Return the at var{i,j}-th element of @var{cell}.\n\ at end deftypefn") { octave_value retval; int i=-1,j=-1; if (args.length() < 2 || args.length() > 3) { print_usage ("nth"); return retval; } i = args(1).int_value (true); if (error_state || i < 1) { error ("cellget: second argument must be a positive integer"); return retval; } if (args.length() == 3) { j = args(2).int_value (true); if (error_state || j < 1) { error ("cellget: third argument must be a positive integer"); return retval; } } Cell cell = args(0).cell_value (); if (! error_state) { int nr = cell.rows(); int nc = cell.columns(); if (j == -1) if (nr == 1) if (i <= nc) retval = cell(0,i-1); else error ("cellget: index = %d out of range", i); else if (nc == 1) if (i <= nr) retval = cell(i-1,0); else error ("cellget: index = %d out of range", i); else error ("cellget: single index not valid for 2-D cell array"); else if (i <= nr && j <= nc) retval = cell(i-1, j-1); else error ("cellget: index = %d,%d out of range", i, j); } else error ("cellget: first argument must be a list or cell"); return retval; } On Thu, Feb 15, 2001 at 05:47:56PM +0100, Daniel Heiserer wrote: > How can I get a matrix I put into a cell? > Whatever operation I apply the cell returns a cell. > I need the basic datatype somewhen. > > thanks daniel > > octave-2.1.31:6> a={1,rand(3),'jonny'} > a = > { > [1,1] = 1 > [1,2] = > > 0.14950 0.69857 0.99893 > 0.49560 0.54115 0.17106 > 0.32942 0.34194 0.17245 > > [1,3] = jonny > } > octave-2.1.31:7> b=a(1,2) > b = > { > [1,1] = > > 0.14950 0.69857 0.99893 > 0.49560 0.54115 0.17106 > 0.32942 0.34194 0.17245 > > } > > Thanks daniel Content-Description: Card for Daniel Heiserer ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------