簡體   English   中英

使用python運行matlab .m文件

[英]running matlab .m file using python

我有一個matlab文件(.m),我想使用python運行此文件。 我的ubuntu系統上沒有matlab。 我仍然可以運行matlab文件嗎?

異調

% Checks vector v for monotonicity, and returns the direction (increasing,  
% decreasing, constant, or none).
%
% Meaning of parameter tol:
% - if tol==0, check for non-increasing or non-decreasing sequence (default).
% - if tol>0, allow backward steps of size <= tol
% - if tol<0, require forward steps of size >= tol
%
% Inputs
%  v:   vector to check for monotonicity
%  tol: see above
% 
% Outputs
%  b: a bitfield indicating monotonicity.  Can be tested as follows:
%   bitand(b,1)==true  -->  v is increasing (within tolerance)
%   bitand(b,2)==true  -->  v is decreasing (within tolerance)
%   bitand(b,3)==true  -->  v is both increasing and decreasing
%                           (i.e. v is constant, within tolerance).
% --------------------------------------------------------------------------
function b = ismonotone( v, tol )
  if ( nargin < 2 )
    tol = 0;
  end

  b = 0;
  dv = diff(v);
  if ( min(dv) >= -tol ) b = bitor( b, 1 ); end
  if ( max(dv) <= tol ) b = bitor( b, 2 ); end
end


%!test assert(ismonotone(linspace(0,1,20)),1);
%!test assert(ismonotone(linspace(1,0,20)),2);
%!test assert(ismonotone(zeros(1,100)),3);
%!test
%! v=[0 -0.01 0 0 0.01 0.25 1];
%! assert(ismonotone(v,0.011),1);
%! assert(ismonotone(-v,0.011),2);

我可以在沒有ubuntu的情況下使用python運行此文件嗎?

您可以從Ubuntu存儲庫安裝Octave (或下載並安裝最新版本-要做更多工作)

在此文件所在的目錄中啟動Octave ,可以運行%! 測試,因此:

octave:1> test ismonotone
PASSES 4 out of 4 tests

實際上那些%!的存在%! 建議此文件最初是為Octave編寫的。 有人可以確認MATLAB是否可以處理像doctest這樣的行嗎?

編輯-添加交互式示例

octave:1> ismonotone(linspace(0,1,20))
ans =  1
octave:2> ismonotone(zeros(1,100))
ans =  3

或者從linux shell

1424:~/myml$ octave -fq --eval 'ismonotone(linspace(0,1,20))'
ans =  1

對於以前從shell運行Python腳本的人來說,Octave比MATLAB更友好。 啟動開銷要小得多,並且命令行選項更加熟悉。 在交互方式下, doc將打開一個熟悉的UNIX信息系統。

您是否嘗試過:1.從Matlab到Python的小型編譯器 2. LiberMate 3.使用SciPy模塊重寫代碼。

希望這可以幫助

Python無法本地運行Matlab程序。 您需要 Python改寫這個,可能使用SciPy的庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM