Getting octave to plot when invoking a function from the command line

后端 未结 6 1792
灰色年华
灰色年华 2020-12-06 13:14

I am trying to run a function in octave from the command line. The function is currently run like so:

octave --silent --persist --eval \'functio

6条回答
  •  悲哀的现实
    2020-12-06 13:40

    The problem is that when you run from command line, when it ends, the plot windows disappear with it.

    #! /usr/bin/octave -qf
    f = figure;
    set(f, "visible", "off")
    
    t=0:0.001:5*pi;
    plot(t, sin(5*t)), grid
    
    print("MyPNG.png", "-dpng")
    

    This saves output to MyPNG.png in the directory where it is run.

    Then you might open it with a visualization program.

    Another option is to add

    pause
    

    at the end of the program so it waits for user input to terminate, therefore to close the plot window.

    Cheers :)

提交回复
热议问题