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

削除された内容 追加された内容
セル配列
構造体
57 行
</source>
 
=== 行列 ===
<source lang="cpp">
#include <octave/oct.h>
92 行
文字列
 
=== 構造体 ===
* Ref[https://www.gnu.org/software/octave/doc/interpreter/Structures-in-Oct_002dFiles.html#Structures-in-Oct_002dFiles A.1.5 Structures in Oct-Files]
 
<source lang="cpp">
#include <octave/oct.h>
#include <octave/ov-struct.h>
DEFUN_DLD (oct_structdemo, args, , "Struct Demo")
{
octave_value retval;
int nargin = args.length ();
if (args.length () == 2) {
octave_scalar_map arg0 = args(0).scalar_map_value ();
//octave_map arg0 = args(0).map_value();
if ( ! error_state ) {
std::string arg1 = args(1).string_value ();
if ( ! error_state ) {
octave_value tmp = arg0.contents (arg1);
//octave_value tmp = arg0.contents (arg1)(0);
if ( tmp.is_defined() ) {
octave_scalar_map st;
st.assign ("selected", tmp);
retval = octave_value (st);
} else {
error("structdemo: struct does not have a field named '%s'\n",
arg1.c_str ());
}
} else {
error ("structdemo: ARG2 must be a character string");
}
} else {
error ("structdemo: ARG1 must be a struct");
}
} else {
print_usage ();
}
return retval;
}
</source>
実行例
<source lang="matlab">
x.a = 1;
x.b="test";
x.c=[1, 2];
oct_structdemo (x, "b")
⇒ selected = test
</source>
 
=== セル配列 ===