「GNU Octave/Octファイル」の版間の差分

削除された内容 追加された内容
M 実行列
セル配列
94 行
構造体
 
=== セル配列 ===
 
* Ref [https://www.gnu.org/software/octave/doc/interpreter/Cell-Arrays-in-Oct_002dFiles.html#Cell-Arrays-in-Oct_002dFiles A.1.4 Cell Arrays in Oct-Files]
<source lang="cpp">
#include <octave/oct.h>
#include <octave/Cell.h>
DEFUN_DLD (oct_celldemo, args, ,
"b=oct_celldemo(c);,c is a cell, b are elements.")
{
octave_value_list retval;
int nargin = args.length();
if (nargin != 1) {
print_usage();
} else {
Cell c = args(0).cell_value();
if ( ! error_state ) {
for ( octave_idx_type i = 0; i < c.numel(); ++i ) {
retval(i) = c(i); // using operator syntax
//retval(i) = c.elem (i); // using method syntax
}
}
}
return retval;
}
</source>
 
実行例
<source lang="cpp">
[b1, b2, b3] = oct_celldemo({1, [1, 2], "test"})
b1 = 1
b2 =
 
1 2
 
b3 = test
</source>