MATLAB: Print contents of uipanel to PNG image

帅比萌擦擦* 提交于 2019-12-06 05:27:19

Why don't you just scroll your panel and grab the frames and concatenate them all together? Here's some code that will basically do that. I would have posted am image, but I guess I don't have enough points for that. You may need to fiddle with the scrolling, and maybe making the slider invisible, but it works.

function printPanel(pnl,filename)




fig  = figure(ancestor(pnl,'figure'));

pnl_units = get(pnl,'units');
fig_units = get(fig,'units');

set(pnl,'units','pixels')
set(fig,'units','pixels')

pnl_rect = getpixelposition(pnl);
fig_rect = getpixelposition(fig);

pnl_height = pnl_rect(4);
fig_height = fig_rect(4);

pnl_rect(2) = -pnl_height;
set(pnl,'position',pnl_rect)


N = ceil(pnl_height/fig_height);

CDATA = cell(N,1);

for i = 1:N
    F = getframe(fig);
    CDATA{i} = F.cdata;
    pnl_rect(2) = pnl_rect(2)+fig_height;
    set(pnl,'position',pnl_rect)
    drawnow
end


set(pnl,'units',pnl_units)
set(fig,'units',fig_units)

imwrite(cat(1,CDATA{:}),filename)
end
  • You could get rid of the ui elements and just make a figure with all the subplots, and then export that one, using e.g. print -dpng ....

  • 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.

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