comparison src/ov-cell.cc @ 10122:9d1a14e12431

Update docs and add tests for container functions
author Thorsten Meyer <thorsten.meyier@gmx.de>
date Sun, 17 Jan 2010 13:31:42 +0100
parents 64a06079cae4
children 829e69ec3110
comparison
equal deleted inserted replaced
10121:b5cc666da6ca 10122:9d1a14e12431
1337 "-*- texinfo -*-\n\ 1337 "-*- texinfo -*-\n\
1338 @deftypefn {Built-in Function} {} struct2cell (@var{S})\n\ 1338 @deftypefn {Built-in Function} {} struct2cell (@var{S})\n\
1339 Create a new cell array from the objects stored in the struct object.\n\ 1339 Create a new cell array from the objects stored in the struct object.\n\
1340 If @var{f} is the number of fields in the structure, the resulting\n\ 1340 If @var{f} is the number of fields in the structure, the resulting\n\
1341 cell array will have a dimension vector corresponding to\n\ 1341 cell array will have a dimension vector corresponding to\n\
1342 @code{[@var{F} size(@var{S})]}.\n\ 1342 @code{[@var{F} size(@var{S})]}. For example:\n\
1343 \n\
1344 @example\n\
1345 @group\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\
1349 c(1,1,:)(:)\n\
1350 @result{} ans =\n\
1351 @{\n\
1352 [1,1] = Peter\n\
1353 [2,1] = Hannah\n\
1354 [3,1] = Robert\n\
1355 @}\n\
1356 c(2,1,:)(:)\n\
1357 @result{} ans =\n\
1358 @{\n\
1359 [1,1] = 23\n\
1360 [2,1] = 16\n\
1361 [3,1] = 3\n\
1362 @}\n\
1363 @end group\n\
1364 @end example\n\
1365 \n\
1343 @seealso{cell2struct, fieldnames}\n\ 1366 @seealso{cell2struct, fieldnames}\n\
1344 @end deftypefn") 1367 @end deftypefn")
1345 { 1368 {
1346 octave_value retval; 1369 octave_value retval;
1347 1370
1399 else 1422 else
1400 print_usage (); 1423 print_usage ();
1401 1424
1402 return retval; 1425 return retval;
1403 } 1426 }
1427
1428 /*
1429 %!test
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);
1435 %! assert (s, t);
1436 %! assert (struct2cell (s), [vals{:}]');
1437 %! assert (fieldnames (s), keys');
1438 */
1404 1439
1405 mxArray * 1440 mxArray *
1406 octave_cell::as_mxArray (void) const 1441 octave_cell::as_mxArray (void) const
1407 { 1442 {
1408 mxArray *retval = new mxArray (dims ()); 1443 mxArray *retval = new mxArray (dims ());