Search code examples
python-3.xsubprocessoctave

Write an Octave command line in Python and extract the outputs


I am willing to call Octave from my python script without using the python package oct2py (I'm having troubles importing it). I am aware of the use of the subprocess package, but how can I extract the output of an Octave function from this command. I rephrase: say I have a function that computes the fft defined as follows: function [A,f]=fft_of_signal(Value,T)%coumputes A and f end

Calling this from Octave goes as follows: octave:1> [v,f]=fft_of_signal(value,T).

How can I use subprocess to ask for the computed values of v and f? subprocess.run(['octave-cli.exe','[v,f]=fft_of_signal(value,T);'])?

Thanks in advance!


Solution

  • Dont.

    Instead, create an octave script which saves any desired outputs in a .mat file and then exits.

    Then, open the .mat file from python using scipy.io.loadmat