Using octave headless

风流意气都作罢 提交于 2019-12-12 08:39:58

问题


Is there a possibility to use Octave headless.

Something like this octave < "5+4" >result.txt


回答1:


Using

octave --silent --eval 5+4 > result.txt

you'll get

ans =  9

in result.txt. See octave --help for details about command-line arguments.

Yet, there is this infamous ans = that might be remove using sed, e.g.

octave --silent --eval 'x=5+4; y=x+1; disp(y)' | sed -e 's/ans = //' >> result.txt

which add the appropriate result (10) in result.txt.

It should not be too hard to wrap this into a bash script.




回答2:


Well there is always the option of writing a script file which saves the results of your computations to a text file. Then when invoking octave you just do:

octave scriptname.m

for example: testfile.m

Return = 5+4;
save('results.txt','Return')

Then from the command line:

octave -q testfile.m

and you should get the results you want in a file called results.txt and it will immediately terminate after. Is there some reason why this option wont work?



来源:https://stackoverflow.com/questions/5903373/using-octave-headless

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!