68 return matrix.index (idx, resize_ok);
94 matrix.delete_elements (idx);
134 error (
"assignment to cell array failed");
139 const std::list<octave_value_list>& idx,
141 const std::list<octave_lvalue> *lvalue_list)
160 retval(0) = tcell(0,0);
170 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
183 retval = (lvalue_list
184 ? retval(0).next_subsref (nargout, type, idx, lvalue_list)
185 : retval(0).next_subsref (nargout, type, idx));
192 const std::list<octave_value_list>& idx,
222 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
242 const std::list<octave_value_list>& idx,
253 if (idx.front ().empty ())
255 error (
"missing index in indexed assignment");
274 return tmp.
subsasgn (type, idx, rhs);
285 std::list<octave_value_list> next_idx (idx);
287 next_idx.erase (next_idx.begin ());
291 t_rhs = tmp.
subsasgn (type.substr (1), next_idx, rhs);
304 std::list<octave_value_list> next_idx (idx);
306 next_idx.erase (next_idx.begin ());
308 std::string next_type = type.substr (1);
310 if (tmpc.
numel () == 1)
325 t_rhs = tmp.
subsasgn (next_type, next_idx, rhs);
342 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
389 if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel ();
391 if (didx.numel () == tmp_cell.
numel ())
392 tmp_cell = tmp_cell.
reshape (didx);
426 return tmp.
subsasgn (type, idx, rhs);
431 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
503 tmp = tmp.
sort (dim, mode);
509 error (
"sort: only cell arrays of character strings may be sorted");
524 tmp = tmp.
sort (sidx, dim, mode);
530 error (
"sort: only cell arrays of character strings may be sorted");
547 error (
"issorted: A is not a cell array of strings");
565 error (
"sortrows: only cell arrays of character strings may be sorted");
582 error (
"issorted: A is not a cell array of strings");
590 error (
"invalid conversion from cell array to logical value");
611 std::queue<string_vector> strvec_queue;
622 n_elts += s_len ? s_len : 1;
626 if (s_max_len > max_len)
629 strvec_queue.push (s);
647 std::string t = s[j];
650 if (pad && max_len > t_len)
651 t += std::string (max_len - t_len,
' ');
657 retval[k++] = std::string (max_len,
' ');
659 retval[k++] = std::string ();
678 error (
"invalid conversion from cell array to array of strings");
705 if (nr > 0 && nc > 0)
720 std::ostringstream buf;
721 buf <<
"[" << i+1 <<
"," << j+1 <<
"]";
740 os <<
"(" << nr <<
"x" << nc <<
")";
748 os <<
"{" << dv.
str () <<
" Cell Array}";
759 #define CELL_ELT_TAG "<cell-element>"
767 os <<
"# ndims: " << d.
length () <<
"\n";
769 for (
int i = 0; i < d.
length (); i++)
790 os <<
"# rows: " <<
rows () <<
"\n"
791 <<
"# columns: " <<
columns () <<
"\n";
824 keywords[0] =
"ndims";
825 keywords[1] =
"rows";
834 int mdims =
static_cast<int> (val);
841 for (
int i = 0; i < mdims; i++)
862 error (
"load: cell array element had unexpected name");
872 error (
"load: failed to load matrix constant");
878 error (
"load: failed to extract number of rows and columns");
882 else if (kw ==
"rows")
889 if (nr > 0 && nc > 0)
907 tmp.
elem (i, j) = t2;
911 error (
"load: cell array element had unexpected name");
913 goto cell_read_error;
924 error (
"load: failed to load cell element");
928 else if (nr == 0 || nc == 0)
935 error (
"load: failed to extract number of rows and columns for cell array");
944 error (
"load: failed to extract number of rows and columns");
959 int32_t di = - d.
length ();
960 os.write (reinterpret_cast<char *> (&di), 4);
961 for (
int i = 0; i < d.
length (); i++)
964 os.write (reinterpret_cast<char *> (&di), 4);
992 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
1004 for (
int i = 0; i < mdims; i++)
1006 if (! is.read (reinterpret_cast<char *> (&di), 4))
1045 error (
"load: cell array element had unexpected name");
1055 error (
"load: failed to load matrix constant");
1069 #if defined (HAVE_HDF5)
1079 hsize_t rank = dv.
length ();
1080 hid_t space_hid = -1, data_hid = -1, size_hid = -1;
1083 data_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1085 data_hid = H5Gcreate (loc_id, name, 0);
1094 space_hid = H5Screate_simple (1, &rank, 0);
1098 H5Gclose (data_hid);
1105 for (hsize_t i = 0; i < rank; i++)
1106 hdims[i] = dv(rank-i-1);
1109 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1110 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1112 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1117 H5Sclose (space_hid);
1118 H5Gclose (data_hid);
1123 H5P_DEFAULT, hdims) < 0)
1125 H5Dclose (size_hid);
1126 H5Sclose (space_hid);
1127 H5Gclose (data_hid);
1131 H5Dclose (size_hid);
1132 H5Sclose (space_hid);
1142 std::ostringstream buf;
1143 int digits =
static_cast<int> (
gnulib::floor (::log10 (static_cast<double>
1145 buf <<
"_" << std::setw (digits) << std::setfill (
'0') << i;
1146 std::string s = buf.str ();
1151 H5Gclose (data_hid);
1156 H5Gclose (data_hid);
1166 bool retval =
false;
1176 hid_t group_id = H5Gopen (loc_id, name, H5P_DEFAULT);
1178 hid_t group_id = H5Gopen (loc_id, name);
1185 hid_t data_hid = H5Dopen (group_id,
"dims", H5P_DEFAULT);
1187 hid_t data_hid = H5Dopen (group_id,
"dims");
1189 hid_t space_hid = H5Dget_space (data_hid);
1190 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
1193 H5Dclose (data_hid);
1194 H5Gclose (group_id);
1201 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
1210 H5P_DEFAULT, tmp) < 0)
1212 H5Dclose (data_hid);
1213 H5Gclose (group_id);
1217 H5Dclose (data_hid);
1218 H5Gclose (group_id);
1220 for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--)
1225 herr_t retval2 = -1;
1229 int current_item = 0;
1231 hsize_t num_obj = 0;
1233 group_id = H5Gopen (loc_id, name, H5P_DEFAULT);
1235 group_id = H5Gopen (loc_id, name);
1237 H5Gget_num_objs (group_id, &num_obj);
1238 H5Gclose (group_id);
1243 if (current_item >= static_cast<int> (num_obj))
1246 retval2 = H5Giterate (loc_id, name, ¤t_item,
1270 @deftypefn {Built-in Function} {} iscell (@var{x})\n\
1271 Return true if @var{x} is a cell array object.\n\
1272 @seealso{ismatrix, isstruct, iscellstr, isa}\n\
1277 if (args.length () == 1)
1287 @deftypefn {Built-in Function} {} cell (@var{n})\n\
1288 @deftypefnx {Built-in Function} {} cell (@var{m}, @var{n})\n\
1289 @deftypefnx {Built-in Function} {} cell (@var{m}, @var{n}, @var{k}, @dots{})\n\
1290 @deftypefnx {Built-in Function} {} cell ([@var{m} @var{n} @dots{}])\n\
1291 Create a new cell array object.\n\
1292 If invoked with a single scalar integer argument, return a square\n\
1293 @nospell{NxN} cell array. If invoked with two or more scalar\n\
1294 integer arguments, or a vector of integer values, return an array with\n\
1295 the given dimensions.\n\
1300 int nargin = args.
length ();
1318 for (
int i = 0; i < nargin; i++)
1320 dims(i) = args(i).is_empty () ? 0 : args(i).nint_value ();
1324 error (
"cell: expecting scalar arguments");
1347 @deftypefn {Built-in Function} {} iscellstr (@var{cell})\n\
1348 Return true if every element of the cell array @var{cell} is a\n\
1349 character string.\n\
1355 if (args.length () == 1)
1370 @deftypefn {Built-in Function} {} cellstr (@var{string})\n\
1371 Create a new cell array object from the elements of the string\n\
1372 array @var{string}.\n\
1377 if (args.length () == 1)
1392 error (
"cellstr: argument STRING must be a 2-D character array");
1403 @deftypefn {Built-in Function} {} struct2cell (@var{S})\n\
1404 Create a new cell array from the objects stored in the struct object.\n\
1405 If @var{f} is the number of fields in the structure, the resulting\n\
1406 cell array will have a dimension vector corresponding to\n\
1407 @code{[@var{F} size(@var{S})]}. For example:\n\
1411 s = struct (\"name\", @{\"Peter\", \"Hannah\", \"Robert\"@},\n\
1412 \"age\", @{23, 16, 3@});\n\
1413 c = struct2cell (s)\n\
1414 @result{} c = @{2x1x3 Cell Array@}\n\
1432 @seealso{cell2struct, fieldnames}\n\
1437 int nargin = args.
length ();
1454 if (m_dv (m_dv.
length () - 1) == 1)
1459 result_dv(0) = num_fields;
1461 for (
int i = 1; i < result_dv.
length (); i++)
1462 result_dv(i) = m_dv(i-1);
1477 error (
"struct2cell: argument S must be a structure");
1508 for (
mwIndex i = 0; i < nel; i++)
1519 #define FORWARD_MAPPER(UMAP) \
1520 case umap_ ## UMAP: \
1521 return matrix.UMAP ()