How to port from Matlab to Headless Octave for Web

前端 未结 2 1564
北荒
北荒 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条回答
  • 2021-01-28 10:33

    I downloaded and installed Octave onto an Ubuntu Mace OS running on VMware on my Mac. This part was seamless and easy. First I tested my code in headless mode with Matlab on the Mac with this command:

    /Applications/MATLAB_R2018a.app/bin/matlab -nodisplay  -nosplash -nodesktop -r "run('mycode.m');quit;"
    

    It produced the correct output which is a plot with four graphs saved as a jpeg and some analysis text to stdout.

    Then I switched to the Ubuntu machine with Octave. This resulted in multiple failures. Octave is missing many of the functions that are in the Matlab core. Like readtable(), which reads in a csv file. It's also missing the notion of a table object. So with that, I was kind of dead in the water.

    I started the interactive version of Octave to see what efficacy it had, and plot would not work. To make plot() function I did had to do the following:

    graphics_toolkit ("gnuplot");
    

    Plot then worked very well and was pretty consistent with Matlab after that, but too much else was missing from it to port my project over without considerable effort and a completely new code branch.

    All this said, I think Octave is a very nice tool, but I also believe that it is so considerably divergent from Matlab 2018a that using the two interchangeably is nearly impossible.

    I called Mathworks and my license allows me to run 2 copies, but what I didn't know is they don't have to be on the same OS. So I can install a Linux version on my data server and continue to develop on my Mac. Problem solved. Thank you Mathworks.

    0 讨论(0)
  • 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.
    
    0 讨论(0)
提交回复
热议问题