使用matlab生产服务器(MPS)和webfigure

时间:2016-02-21 05:01:44

标签: servlets matlab-deployment

我想知道如何从matlab传递一个绘图,以便在servlet页面上显示为webfigure。请注意,我使用的是MPS。因此,我没有将matlab代码打包到java中,而只是将客户端代理打包到matlab函数中。

我的matlab函数:

function varargout = mymagicplot(in,displayPlot)
    x = magic(in);
    varargout{1} = x;
    if (strcmp(displayPlot, 'Plot'))
       varargout{2} = {plot(x)};
end

在servlet端:

interface MatlabMagic {
  public Object[] mymagicplot(int num_outargs, int size, String plotOption) throws IOException, MATLABException;
}

问题是如何将绘图的显示编码为servlet页面上的webfigure?

1 个答案:

答案 0 :(得分:0)

我尝试通过将我的matlab代码分成两个函数来解决这个问题。

客户端代理使用第一个函数。

function m = mymagic(in)
    m = magic(in);
end

第二个函数由库编译器打包到java类中。

function returnfigure = mygetwebfiguremagicplot(in)
   h = figure;
   set(h, 'Visible', 'off');
   plot(in);
   returnfigure = webfigure(h);
   close(h);
end

通过这种方式,我可以访问MPS中的mymagic函数.ctf,将结果返回给servlet,并使用从第二个函数matlab代码创建的java类将其绘制为webfigure。

这只是我能想到的一种可行的解决方案。