MATLAB:将uipanel的内容打印到PNG图像 [英] MATLAB: Print contents of uipanel to PNG image

查看:155
本文介绍了MATLAB:将uipanel的内容打印到PNG图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何在MATLAB中完成以下任务.我有一个看起来像这样的图:

I don't know how to accomplish the following in MATLAB. I have a figure which looks like this:

在图中,我有一个包含许多子图的面板和一个滚动条,可让我查看面板的一部分.

In the figure, I have a panel with many subplots and a scrollbar that allows me to view a portion of the panel.

我想将面板的整个内容保存到PNG图像文件(而不仅仅是可见部分),即我想要一个高大的矩形文件,而不是需要滚动.

I want to save the whole contents of the panel to a PNG image file (not just the visible portion), i.e. I want to have a file which is a tall rectangle, and doesn't require scrolling.

生成图形的代码如下:

function draw(obj)
       figure;
       panel1 = uipanel('Parent',1);
       panel2 = uipanel('Parent',panel1);
       panelheight = obj.nIterations / 2;
       set(panel1,'Position',[0 0 0.97 1]);
       set(panel2,'Position',[0 1-panelheight 1 panelheight]); %%
       nPlot = 1;
       for i=1:obj.nIterations
            models = obj.iterations{i};
            for nModel=1:length(models)
                subplot(obj.nIterations,length(models)*2,nPlot);
                nPlot = nPlot + 1;
                drawTransitions(models{nModel});
                set(gca,'Parent',panel2);
                subplot(obj.nIterations,length(models)*2,nPlot);
                nPlot = nPlot + 1;
                drawRewards(models{nModel});
                set(gca,'Parent',panel2);
            end
       end
       s = uicontrol('Style','Slider','Parent',1,...
        'Units','normalized','Position',[0.97 0 0.03 1],...
        'Value',1,'Callback',{@slider_callback1,panel2,panelheight});
end

我尝试了以下方法,但没有成功.

I have tried the following, without success.

  1. saveas功能可保存整个图形,而不仅仅是面板.另外,它会修剪面板的不可见部分.
  2. export_fig(panel2.'file.png')仅给出纯灰色图像.
  1. The saveas funstion saves the whole figure, not just the panel. Also, it clips the invisible portion of the panel.
  2. export_fig(panel2.'file.png') gives just a solid gray image.

推荐答案

  • 您可以摆脱ui元素,仅用所有子图制作一个图形,然后使用例如将其导出. print -dpng ....

    saveas将句柄作为第一个参数.也许这不一定是图形或模型的句柄,但可能是对面板内容的引用.

    saveas takes a handle as a first argument. Maybe this does not have to be a figure or model handle, but could be a reference to the contents of the panel.

    这篇关于MATLAB:将uipanel的内容打印到PNG图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆