4

我最近安装了 oct2py 及其依赖项,以便导入一些要在我的 python 代码中使用的 matlab 函数。.m 文件与我的 python 代码位于同一目录中。

考虑到实际函数是在 octave/matlab 中定义的,您能否帮我弄清楚我将如何导入这些 .m 文件以及其中的方法以及如何在我的 python 代码中使用这些函数。我已经包含了一个带有函数的示例 .m 文件

function x=readfile(y)
%  Puts the contents of a text file with path and name
%  specified in string y, into char array x.
%      Example:  mystring = readfile('c:\workdir\readme.txt');


fid = fopen(y,'r');     %  Read the Plaintext
M = fread(fid);
fclose(fid);  
x = char(M');

上述函数位于与我的 python 代码相同的目录中名为“readfile.m”的文件中。

4

2 回答 2

1

这很简单

from oct2py import octave
octave.feval( 'readfile', 'your_input_file_here.txt' )

PS。您的 octave 可执行文件需要在系统路径中可用。

于 2019-02-11T18:07:28.973 回答
0

所以显然 octave 4 在 bin 中没有“octave.exe”,但是 octave 3 有,并且与 oct2py 完美配合

于 2019-02-12T10:05:49.773 回答