How to port from Matlab to Headless Octave for Web

江枫思渺然 提交于 2020-06-18 04:46:48

问题


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.

I've read that the "--no-window-system" will allow me to run headless, and I know that I can use "saveas(fig,FileName,format)" to save my figures. My question is will plot() and histogram() work without a head in Octave, and if so how do I go about this? (I want the figures to go to gifs or jpegs that I'll reference in a web page.)

TIA


回答1:


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.



回答2:


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.



来源:https://stackoverflow.com/questions/53575015/how-to-port-from-matlab-to-headless-octave-for-web

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