How to port from Matlab to Headless Octave for Web

前端 未结 2 1566
北荒
北荒 2021-01-28 10:05

I have a Matlab application that I wrote and would like to put on a AWS server running Octave to make a service publicly available via the web. I\'ve never used Octave.

2条回答
  •  -上瘾入骨i
    2021-01-28 10:42

    In theory it should work as expected.

    Things to keep in mind and try to work around include the following:

    1. If your environment does not provide an X DISPLAY, only the gnuplot graphics toolkit will be available. If you'd like to 'fake' an x display to allow you use of other graphics toolkits (e.g. graphics_toolkit('qt')), consider running octave via xvfb-run, which simulates a 'dumb' x server. (i.e. launch octave as xvfb-run octave, see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=805295 ).

    2. Occasionally OpenGl complains when you try to plot things that are 'offscreen'. This problem can be worked around if your images are set to non-visible as default, which still allows them to be printed without necessarily appearing on screen. To do this, set the 'root' figure object to non-visible before plotting anything:

      set(0, 'defaultfigurevisible', 'off')
      

    Concretely, your code might look like this:

    gnuplot_toolkit('qt';)   # optional, if run via xvfb-run or the AWS supports an X Display
    set(0, 'defaultfigurevisible', 'off');
    h = plot( 1 : 10 );
    saveas( h, 'out.png', 'png' ); # you can replace 'png' with 'gif' or 'jpg' etc.
    

提交回复
热议问题