Octave doesn't plot from external file

你。 提交于 2019-12-20 02:29:11

问题


If I type octave on terminal and then:

x = linspace(0, 2*pi, 100);
y = sin(x);
plot(x, y);

the graphic correctly shows the plot. That's what I tried: I created a text file named gettingStarted.m where I wrote the three lines above inside of it, in order to execute this file with Octave. I type octave gettingStarted.m but the plot doesn't appear. Does not plotting work if you run an external file with Octave?

I'm working on Ubuntu 12.04, 32 bit


回答1:


If you are running an Octave script that includes a plotting command, once the script finishes, so does Octave. This will of course close the plot window. Remember that the plot window is also Octave, so when process end, so does the other. So the plot window does show up, but immediately closes when Octave finishes execution.

A common solution is to put a pause command at the end of your script. To view the plot window for a specific amount of time and close the window automatically use pause(n) which pauses the execution for n seconds before continuing.

A less ideal alternative, is to call the script with octave --persistent path-to-script to go interactive at the end.

See also, Octave's FAQ entry, When I try plotting from a script, why am I not seeing anything?



来源:https://stackoverflow.com/questions/19081004/octave-doesnt-plot-from-external-file

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