开发者

Is there something equivalent to C's #include in Octave?

Suppose that I have 2 scripts:

magic_f开发者_高级运维unction.m:

function retval = magic(x)
    retval = 12345678;
endfunction

other_script.m

#some code
X = magic(17)

What should I add to other_script.m in order to make function "magic" visible?


Judging by the documentation of Functions and Script Files, it should be sufficient to put the function in a file named magic.m in a directory specified in LOADPATH.

When Octave encounters an identifier that is undefined, it first looks for variables or functions that are already compiled and currently listed in its symbol table. If it fails to find a definition there, it searches the list of directories specified by the built-in variable LOADPATH for files ending in `.m' that have the same base name as the undefined identifier.(4) Once Octave finds a file with a name that matches, the contents of the file are read. If it defines a single function, it is compiled and executed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜