繁体   English   中英

使用oct2py的难度

[英]Difficulty using oct2py

我最近安装了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”的文件中。

这很简单

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

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

因此,显然八度音阶4的bin中没有'octave.exe',但是八度音阶3确实如此,并且与oct2py完美兼容

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM