Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
715 views
in Technique[技术] by (71.8m points)

subprocess - 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!

question from:https://stackoverflow.com/questions/65844136/write-an-octave-command-line-in-python-and-extract-the-outputs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...