3Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
6This file is part of Octave.
8Octave is free software; you can redistribute it and/or modify it
9under the terms of the GNU General Public License as published by the
10Free Software Foundation; either version 3 of the License, or (at your
11option) any later version.
13Octave is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18You should have received a copy of the GNU General Public License
19along with Octave; see the file COPYING. If not, see
20<http://www.gnu.org/licenses/>.
34#include "Array-util.h"
38#include "oct-locbuf.h"
44#include "unwind-prot.h"
46#include "ov-base-mat.h"
47#include "ov-base-mat.cc"
54#include "ls-oct-ascii.h"
55#include "ls-oct-binary.h"
59// Cell is able to handle octave_value indexing by itself, so just forward
64octave_base_matrix<Cell>::do_index_op (const octave_value_list& idx,
67 return matrix.index (idx, resize_ok);
72octave_base_matrix<Cell>::assign (const octave_value_list& idx, const Cell& rhs)
74 matrix.assign (idx, rhs);
79octave_base_matrix<Cell>::assign (const octave_value_list& idx, octave_value rhs)
83 matrix.assign (idx, rhs.cell_value ());
85 matrix.assign (idx, Cell (rhs));
90octave_base_matrix<Cell>::delete_elements (const octave_value_list& idx)
92 matrix.delete_elements (idx);
95template class octave_base_matrix<Cell>;
97DEFINE_OCTAVE_ALLOCATOR (octave_cell);
99DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell", "cell");
102gripe_failed_assignment (void)
104 error ("assignment to cell array failed");
108octave_cell::subsref (const std::string& type,
109 const std::list<octave_value_list>& idx,
112 octave_value_list retval;
117 retval(0) = do_index_op (idx.front ());
122 octave_value tmp = do_index_op (idx.front ());
126 Cell tcell = tmp.cell_value ();
128 if (tcell.length () == 1)
129 retval(0) = tcell(0,0);
131 retval = octave_value (octave_value_list (tcell), true);
138 std::string nm = type_name ();
139 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
147 // FIXME -- perhaps there should be an
148 // octave_value_list::next_subsref member function? See also
149 // octave_user_function::subsref.
152 retval = retval(0).next_subsref (nargout, type, idx);
158octave_cell::subsref (const std::string& type,
159 const std::list<octave_value_list>& idx,
167 retval = do_index_op (idx.front (), auto_add);
172 octave_value tmp = do_index_op (idx.front (), auto_add);
176 const Cell tcell = tmp.cell_value ();
178 if (tcell.length () == 1)
181 retval = octave_value (octave_value_list (tcell), true);
188 std::string nm = type_name ();
189 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
197 // FIXME -- perhaps there should be an
198 // octave_value_list::next_subsref member function? See also
199 // octave_user_function::subsref.
202 retval = retval.next_subsref (auto_add, type, idx);
208octave_cell::subsasgn (const std::string& type,
209 const std::list<octave_value_list>& idx,
210 const octave_value& rhs)
214 int n = type.length ();
216 octave_value t_rhs = rhs;
218 clear_cellstr_cache ();
220 if (idx.front ().empty ())
222 error ("missing index in indexed assignment");
232 if (is_empty () && type[1] == '.')
234 // Allow conversion of empty cell array to some other
235 // type in cases like
237 // x = []; x(i).f = rhs
239 octave_value tmp = octave_value::empty_conv (type, rhs);
241 return tmp.subsasgn (type, idx, rhs);
245 octave_value tmp = do_index_op (idx.front (), true);
247 if (! tmp.is_defined ())
248 tmp = octave_value::empty_conv (type.substr (1), rhs);
252 std::list<octave_value_list> next_idx (idx);
254 next_idx.erase (next_idx.begin ());
258 t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs);
266 matrix.make_unique ();
267 Cell tmpc = matrix.index (idx.front (), true);
271 std::list<octave_value_list> next_idx (idx);
273 next_idx.erase (next_idx.begin ());
275 std::string next_type = type.substr (1);
277 if (tmpc.numel () == 1)
279 octave_value tmp = tmpc(0);
282 if (! tmp.is_defined () || tmp.is_zero_by_zero ())
284 tmp = octave_value::empty_conv (type.substr (1), rhs);
285 tmp.make_unique (); // probably a no-op.
288 // optimization: ignore the copy still stored inside our array.
292 t_rhs = tmp.subsasgn (next_type, next_idx, rhs);
295 gripe_indexed_cs_list ();
302 std::string nm = type_name ();
303 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
318 octave_value_list i = idx.front ();
320 if (t_rhs.is_cell ())
321 octave_base_matrix<Cell>::assign (i, t_rhs.cell_value ());
323 if (t_rhs.is_null_value ())
324 octave_base_matrix<Cell>::delete_elements (i);
326 octave_base_matrix<Cell>::assign (i, Cell (t_rhs));
331 retval = octave_value (this);
334 gripe_failed_assignment ();
340 octave_value_list idxf = idx.front ();
342 if (t_rhs.is_cs_list ())
344 Cell tmp_cell = Cell (t_rhs.list_value ());
346 // Inquire the proper shape of the RHS.
348 dim_vector didx = dims ().redim (idxf.length ());
349 for (octave_idx_type k = 0; k < idxf.length (); k++)
350 if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel ();
352 if (didx.numel () == tmp_cell.numel ())
353 tmp_cell = tmp_cell.reshape (didx);
356 octave_base_matrix<Cell>::assign (idxf, tmp_cell);
358 else if (idxf.all_scalars () || do_index_op (idxf, true).numel () == 1)
359 // Regularize a null matrix if stored into a cell.
360 octave_base_matrix<Cell>::assign (idxf, Cell (t_rhs.storable_value ()));
361 else if (! error_state)
362 gripe_nonbraced_cs_list_assignment ();
367 retval = octave_value (this);
370 gripe_failed_assignment ();
376 std::string nm = type_name ();
377 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
390octave_cell::is_cellstr (void) const
393 if (cellstr_cache.get ())
397 retval = matrix.is_cellstr ();
398 // Allocate empty cache to mark that this is indeed a cellstr.
400 cellstr_cache.reset (new Array<std::string> ());
407octave_cell::assign (const octave_value_list& idx, const Cell& rhs)
409 clear_cellstr_cache ();
410 octave_base_matrix<Cell>::assign (idx, rhs);
414octave_cell::assign (const octave_value_list& idx, const octave_value& rhs)
416 clear_cellstr_cache ();
417 octave_base_matrix<Cell>::assign (idx, rhs);
422octave_cell::delete_elements (const octave_value_list& idx)
424 clear_cellstr_cache ();
425 octave_base_matrix<Cell>::delete_elements (idx);
429octave_cell::byte_size (void) const
433 for (octave_idx_type i = 0; i < numel (); i++)
434 retval += matrix(i).byte_size ();
440octave_cell::sort (octave_idx_type dim, sortmode mode) const
446 Array<std::string> tmp = cellstr_value ();
448 tmp = tmp.sort (dim, mode);
450 // We already have the cache.
451 retval = new octave_cell (tmp);
454 error ("sort: only cell arrays of character strings may be sorted");
460octave_cell::sort (Array<octave_idx_type> &sidx, octave_idx_type dim,
467 Array<std::string> tmp = cellstr_value ();
469 tmp = tmp.sort (sidx, dim, mode);
471 // We already have the cache.
472 retval = new octave_cell (tmp);
475 error ("sort: only cell arrays of character strings may be sorted");
481octave_cell::is_sorted (sortmode mode) const
483 sortmode retval = UNSORTED;
487 Array<std::string> tmp = cellstr_value ();
489 retval = tmp.is_sorted (mode);
492 error ("issorted: not a cell array of strings");
498Array<octave_idx_type>
499octave_cell::sort_rows_idx (sortmode mode) const
501 Array<octave_idx_type> retval;
505 Array<std::string> tmp = cellstr_value ();
507 retval = tmp.sort_rows_idx (mode);
510 error ("sortrows: only cell arrays of character strings may be sorted");
516octave_cell::is_sorted_rows (sortmode mode) const
518 sortmode retval = UNSORTED;
522 Array<std::string> tmp = cellstr_value ();
524 retval = tmp.is_sorted_rows (mode);
527 error ("issorted: not a cell array of strings");
533octave_cell::is_true (void) const
535 error ("invalid conversion from cell array to logical value");
540octave_cell::list_value (void) const
542 return octave_value_list (matrix);
546octave_cell::all_strings (bool pad) const
548 string_vector retval;
550 octave_idx_type nel = numel ();
554 octave_idx_type max_len = 0;
556 std::queue<string_vector> strvec_queue;
558 for (octave_idx_type i = 0; i < nel; i++)
560 string_vector s = matrix(i).all_strings ();
565 octave_idx_type s_len = s.length ();
567 n_elts += s_len ? s_len : 1;
569 octave_idx_type s_max_len = s.max_length ();
571 if (s_max_len > max_len)
574 strvec_queue.push (s);
577 retval = string_vector (n_elts);
579 octave_idx_type k = 0;
581 for (octave_idx_type i = 0; i < nel; i++)
583 const string_vector s = strvec_queue.front ();
586 octave_idx_type s_len = s.length ();
590 for (octave_idx_type j = 0; j < s_len; j++)
592 std::string t = s[j];
593 int t_len = t.length ();
595 if (pad && max_len > t_len)
596 t += std::string (max_len - t_len, ' ');
602 retval[k++] = std::string (max_len, ' ');
604 retval[k++] = std::string ();
611octave_cell::cellstr_value (void) const
613 Array<std::string> retval;
617 if (cellstr_cache->is_empty ())
618 *cellstr_cache = matrix.cellstr_value ();
620 return *cellstr_cache;
623 error ("invalid conversion from cell array to array of strings");
629octave_cell::print_as_scalar (void) const
631 return (ndims () > 2 || numel () == 0);
635octave_cell::print (std::ostream& os, bool) const
641octave_cell::print_raw (std::ostream& os, bool) const
643 int nd = matrix.ndims ();
647 octave_idx_type nr = rows ();
648 octave_idx_type nc = columns ();
650 if (nr > 0 && nc > 0)
656 increment_indent_level ();
658 for (octave_idx_type j = 0; j < nc; j++)
660 for (octave_idx_type i = 0; i < nr; i++)
664 std::ostringstream buf;
665 buf << "[" << i+1 << "," << j+1 << "]";
667 octave_value val = matrix(i,j);
669 val.print_with_name (os, buf.str ());
673 decrement_indent_level ();
683 if (Vprint_empty_dimensions)
684 os << "(" << nr << "x" << nc << ")";
691 dim_vector dv = matrix.dims ();
692 os << "{" << dv.str () << " Cell Array}";
697#define CELL_ELT_TAG "<cell-element>"
700octave_cell::save_ascii (std::ostream& os)
702 dim_vector d = dims ();
705 os << "# ndims: " << d.length () << "\n";
707 for (int i = 0; i < d.length (); i++)
711 Cell tmp = cell_value ();
713 for (octave_idx_type i = 0; i < d.numel (); i++)
715 octave_value o_val = tmp.elem (i);
717 // Recurse to print sub-value.
718 bool b = save_ascii_data (os, o_val, CELL_ELT_TAG, false, 0);
726 // Keep this case, rather than use generic code above for backward
727 // compatiability. Makes load_ascii much more complex!!
728 os << "# rows: " << rows () << "\n"
729 << "# columns: " << columns () << "\n";
731 Cell tmp = cell_value ();
733 for (octave_idx_type j = 0; j < tmp.cols (); j++)
735 for (octave_idx_type i = 0; i < tmp.rows (); i++)
737 octave_value o_val = tmp.elem (i, j);
739 // Recurse to print sub-value.
740 bool b = save_ascii_data (os, o_val, CELL_ELT_TAG, false, 0);
754octave_cell::load_ascii (std::istream& is)
758 clear_cellstr_cache ();
760 string_vector keywords(2);
762 keywords[0] = "ndims";
763 keywords[1] = "rows";
766 octave_idx_type val = 0;
768 if (extract_keyword (is, keywords, kw, val, true))
772 int mdims = static_cast<int> (val);
779 for (int i = 0; i < mdims; i++)
784 for (octave_idx_type i = 0; i < dv.numel (); i++)
789 // recurse to read cell elements
790 std::string nm = read_ascii_data (is, std::string (),
793 if (nm == CELL_ELT_TAG)
800 error ("load: cell array element had unexpected name");
810 error ("load: failed to load matrix constant");
816 error ("load: failed to extract number of rows and columns");
820 else if (kw == "rows")
822 octave_idx_type nr = val;
823 octave_idx_type nc = 0;
825 if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0)
827 if (nr > 0 && nc > 0)
831 for (octave_idx_type j = 0; j < nc; j++)
833 for (octave_idx_type i = 0; i < nr; i++)
838 // recurse to read cell elements
839 std::string nm = read_ascii_data (is, std::string (),
842 if (nm == CELL_ELT_TAG)
845 tmp.elem (i, j) = t2;
849 error ("load: cell array element had unexpected name");
851 goto cell_read_error;
862 error ("load: failed to load cell element");
866 else if (nr == 0 || nc == 0)
867 matrix = Cell (nr, nc);
873 error ("load: failed to extract number of rows and columns for cell array");
882 error ("load: failed to extract number of rows and columns");
890octave_cell::save_binary (std::ostream& os, bool& save_as_floats)
892 dim_vector d = dims ();
896 // Use negative value for ndims
897 int32_t di = - d.length();
898 os.write (reinterpret_cast<char *> (&di), 4);
899 for (int i = 0; i < d.length (); i++)
902 os.write (reinterpret_cast<char *> (&di), 4);
905 Cell tmp = cell_value ();
907 for (octave_idx_type i = 0; i < d.numel (); i++)
909 octave_value o_val = tmp.elem (i);
911 // Recurse to print sub-value.
912 bool b = save_binary_data (os, o_val, CELL_ELT_TAG, "", 0,
923octave_cell::load_binary (std::istream& is, bool swap,
924 oct_mach_info::float_format fmt)
926 clear_cellstr_cache ();
930 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
933 swap_bytes<4> (&mdims);
942 for (int i = 0; i < mdims; i++)
944 if (! is.read (reinterpret_cast<char *> (&di), 4))
951 // Convert an array with a single dimension to be a row vector.
952 // Octave should never write files like this, other software
963 octave_idx_type nel = dv.numel ();
966 for (octave_idx_type i = 0; i < nel; i++)
972 // recurse to read cell elements
973 std::string nm = read_binary_data (is, swap, fmt, std::string (),
976 if (nm == CELL_ELT_TAG)
983 error ("load: cell array element had unexpected name");
993 error ("load: failed to load matrix constant");
1001octave_cell::mex_get_data (void) const
1003 clear_cellstr_cache ();
1004 return matrix.mex_get_data ();
1007#if defined (HAVE_HDF5)
1010octave_cell::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats)
1012 dim_vector dv = dims ();
1013 int empty = save_hdf5_empty (loc_id, name, dv);
1017 hsize_t rank = dv.length ();
1018 hid_t space_hid = -1, data_hid = -1, size_hid = -1;
1021 data_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1023 data_hid = H5Gcreate (loc_id, name, 0);
1029 // Have to save cell array shape, since can't have a
1030 // dataset of groups....
1032 space_hid = H5Screate_simple (1, &rank, 0);
1036 H5Gclose (data_hid);
1040 OCTAVE_LOCAL_BUFFER (octave_idx_type, hdims, rank);
1042 // Octave uses column-major, while HDF5 uses row-major ordering
1043 for (hsize_t i = 0; i < rank; i++)
1044 hdims[i] = dv(rank-i-1);
1047 size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, space_hid,
1048 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1050 size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, space_hid,
1055 H5Sclose (space_hid);
1056 H5Gclose (data_hid);
1060 if (H5Dwrite (size_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL,
1061 H5P_DEFAULT, hdims) < 0)
1063 H5Dclose (size_hid);
1064 H5Sclose (space_hid);
1065 H5Gclose (data_hid);
1069 H5Dclose (size_hid);
1070 H5Sclose (space_hid);
1072 // Recursively add each element of the cell to this group.
1074 Cell tmp = cell_value ();
1076 octave_idx_type nel = dv.numel ();
1078 for (octave_idx_type i = 0; i < nel; i++)
1080 std::ostringstream buf;
1081 int digits = static_cast<int> (::floor (::log10 (static_cast<double> (nel)) + 1.0));
1082 buf << "_" << std::setw (digits) << std::setfill ('0') << i;
1083 std::string s = buf.str ();
1085 if (! add_hdf5_data (data_hid, tmp.elem (i), s.c_str (), "", false,
1088 H5Gclose (data_hid);
1093 H5Gclose (data_hid);
1099octave_cell::load_hdf5 (hid_t loc_id, const char *name)
1101 clear_cellstr_cache ();
1103 bool retval = false;
1106 int empty = load_hdf5_empty (loc_id, name, dv);
1113 hid_t group_id = H5Gopen (loc_id, name, H5P_DEFAULT);
1115 hid_t group_id = H5Gopen (loc_id, name);
1122 hid_t data_hid = H5Dopen (group_id, "dims", H5P_DEFAULT);
1124 hid_t data_hid = H5Dopen (group_id, "dims");
1126 hid_t space_hid = H5Dget_space (data_hid);
1127 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
1130 H5Dclose (data_hid);
1131 H5Gclose (group_id);
1135 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
1136 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
1138 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
1140 // Octave uses column-major, while HDF5 uses row-major ordering.
1142 dv.resize (hdims[0]);
1144 OCTAVE_LOCAL_BUFFER (octave_idx_type, tmp, hdims[0]);
1146 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL,
1147 H5P_DEFAULT, tmp) < 0)
1149 H5Dclose (data_hid);
1150 H5Gclose (group_id);
1154 H5Dclose (data_hid);
1155 H5Gclose (group_id);
1157 for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--)
1160 hdf5_callback_data dsub;
1162 herr_t retval2 = -1;
1166 int current_item = 0;
1168 hsize_t num_obj = 0;
1170 group_id = H5Gopen (loc_id, name, H5P_DEFAULT);
1172 group_id = H5Gopen (loc_id, name);
1174 H5Gget_num_objs (group_id, &num_obj);
1175 H5Gclose (group_id);
1177 for (octave_idx_type i = 0; i < dv.numel (); i++)
1180 if (current_item >= static_cast<int> (num_obj))
1183 retval2 = H5Giterate (loc_id, name, ¤t_item,
1184 hdf5_read_next_data, &dsub);
1189 octave_value ov = dsub.tc;
1205DEFUN (iscell, args, ,
1207@deftypefn {Built-in Function} {} iscell (@var{x})\n\
1208Return true if @var{x} is a cell array object. Otherwise, return\n\
1212 octave_value retval;
1214 if (args.length () == 1)
1215 retval = args(0).is_cell ();
1224@deftypefn {Built-in Function} {} cell (@var{x})\n\
1225@deftypefnx {Built-in Function} {} cell (@var{n}, @var{m})\n\
1226Create a new cell array object. If invoked with a single scalar\n\
1227argument, @code{cell} returns a square cell array with the dimension\n\
1228specified. If you supply two scalar arguments, @code{cell} takes\n\
1229them to be the number of rows and columns. If given a vector with two\n\
1230elements, @code{cell} uses the values of the elements as the number of\n\
1231rows and columns, respectively.\n\
1234 octave_value retval;
1236 int nargin = args.length ();
1243 dims = dim_vector (0, 0);
1247 get_dimensions (args(0), "cell", dims);
1252 dims.resize (nargin);
1254 for (int i = 0; i < nargin; i++)
1256 dims(i) = args(i).is_empty () ? 0 : args(i).nint_value ();
1260 error ("cell: expecting scalar arguments");
1270 dims.chop_trailing_singletons ();
1272 check_dimensions (dims, "cell");
1275 retval = Cell (dims, Matrix ());
1281DEFUN (iscellstr, args, ,
1283@deftypefn {Built-in Function} {} iscellstr (@var{cell})\n\
1284Return true if every element of the cell array @var{cell} is a\n\
1288 octave_value retval;
1290 if (args.length () == 1)
1291 retval = args(0).is_cellstr ();
1298// Note that since Fcellstr calls Fiscellstr, we need to have
1299// Fiscellstr defined first (to provide a declaration) and also we
1300// should keep it in the same file (so we don't have to provide a
1301// declaration) and so we don't have to use feval to call it.
1303DEFUN (cellstr, args, ,
1305@deftypefn {Built-in Function} {} cellstr (@var{string})\n\
1306Create a new cell array object from the elements of the string\n\
1307array @var{string}.\n\
1310 octave_value retval;
1312 if (args.length () == 1)
1314 octave_value_list tmp = Fiscellstr (args, 1);
1316 if (tmp(0).is_true ())
1320 string_vector s = args(0).all_strings ();
1323 retval = (s.is_empty ()
1324 ? Cell (octave_value (std::string ()))
1327 error ("cellstr: expecting argument to be a 2-d character array");
1336DEFUN (struct2cell, args, ,
1338@deftypefn {Built-in Function} {} struct2cell (@var{S})\n\
1339Create a new cell array from the objects stored in the struct object.\n\
1340If @var{f} is the number of fields in the structure, the resulting\n\
1341cell array will have a dimension vector corresponding to\n\
1342@code{[@var{F} size(@var{S})]}. For example:\n\
1346 s = struct('name', @{'Peter', 'Hannah', 'Robert'@}, 'age', @{23, 16, 3@});\n\
1347 c = struct2cell(s)\n\
1348 @result{} c = @{1x1x3 Cell Array@}\n\
1366@seealso{cell2struct, fieldnames}\n\
1369 octave_value retval;
1371 int nargin = args.length ();
1375 Octave_map m = args(0).map_value ();
1379 dim_vector m_dv = m.dims ();
1381 string_vector keys = m.keys ();
1383 octave_idx_type num_fields = keys.length ();
1385 // The resulting dim_vector should have dimensions:
1386 // [numel(fields) size(struct)]
1387 // except if the struct is a column vector.
1389 dim_vector result_dv;
1390 if (m_dv (m_dv.length () - 1) == 1)
1391 result_dv.resize (m_dv.length ());
1393 result_dv.resize (m_dv.length () + 1); // Add 1 for the fields.
1395 result_dv(0) = num_fields;
1397 for (int i = 1; i < result_dv.length (); i++)
1398 result_dv(i) = m_dv(i-1);
1402 octave_idx_type n_elts = m.numel ();
1404 for (octave_idx_type j = 0; j < num_fields; j++)
1406 octave_idx_type k = j;
1408 const Cell vals = m.contents (keys(j));
1410 for (octave_idx_type i = 0; i < n_elts; i++)
1420 error ("struct2cell: expecting argument to be a cell array");
1430%! keys = cellstr (char (floor (rand (11,10)*24+65)))';
1431%! vals = cellfun(@(x) mat2cell(rand (19,1), ones (19,1), 1), ...
1432%! mat2cell([1:11]', ones(11,1), 1), "uniformoutput", false)';
1433%! s = struct ([keys; vals]{:});
1434%! t = cell2struct ([vals{:}], keys, 2);
1436%! assert (struct2cell (s), [vals{:}]');
1437%! assert (fieldnames (s), keys');
1441octave_cell::as_mxArray (void) const
1443 mxArray *retval = new mxArray (dims ());
1445 mxArray **elts = static_cast<mxArray **> (retval->get_data ());
1447 mwSize nel = numel ();
1449 const octave_value *p = matrix.data ();
1451 for (mwIndex i = 0; i < nel; i++)
1452 elts[i] = new mxArray (p[i]);
1458octave_cell::map (unary_mapper_t umap) const
1462#define FORWARD_MAPPER(UMAP) \
1463 case umap_ ## UMAP: \
1464 return matrix.UMAP ()
1465 FORWARD_MAPPER (xisalnum);
1466 FORWARD_MAPPER (xisalpha);
1467 FORWARD_MAPPER (xisascii);
1468 FORWARD_MAPPER (xiscntrl);
1469 FORWARD_MAPPER (xisdigit);
1470 FORWARD_MAPPER (xisgraph);
1471 FORWARD_MAPPER (xislower);
1472 FORWARD_MAPPER (xisprint);
1473 FORWARD_MAPPER (xispunct);
1474 FORWARD_MAPPER (xisspace);
1475 FORWARD_MAPPER (xisupper);
1476 FORWARD_MAPPER (xisxdigit);
1477 FORWARD_MAPPER (xtoascii);
1478 FORWARD_MAPPER (xtolower);
1479 FORWARD_MAPPER (xtoupper);
1482 return octave_base_value::map (umap);