1

我正在尝试在MATLAB中打印我的图形,但它一直在搞砸,我不知道为什么。

opslaan = figure(1);
        plot(1:handles.aantal,handles.nauw,'-r','LineWidth',1.5);
        xlabel(gca,sprintf('Framenummer (%g ms per frame)',60/handles.aantal));
        ylabel(gca,'dB');
        set(gca,'YGrid','on');
        yAsMax = ceil( ceil(max(handles.nauw)) / 2) * 2;
        axis([0 handles.aantal 0 yAsMax]);
        pause(1);
        print -dpng image.png 

第一行只是在我的图形上绘制数据,然后标记 x 和 y,打开网格并像我想要的那样计算 y 轴。这一切都很好,MATLAB 在图形窗口中显示它就像我想要的那样。当保存到 .png / .jpeg / .eps 时,它会出错并且只打印左下角(473x355 像素),其余的就消失了。

通过File -> Save As手动导出时,它可以正常工作。

我如何解决它?

4

2 回答 2

3

Making Pretty Graphs这篇文章包含一个关于如何从MATLAB图形生成可发布图像的优秀教程。

通常,以编程方式将图形打印到图像文件应包含以下步骤。

% Some data to be plotted
t1 = 0:0.1:4*pi ;
t2 = 0:0.01:4*pi ;
f1 = sin(t1) + randn(size(t1))/10 ;
f2 = sin(t2) + cos(t2.^2)/10 + randn(size(t2))/100 ;

% Define the styles to be used
linstyle_11 = {'LineStyle','--','Color',[.3 .6 .6],'LineWidth',1} ;
linstyle_12 = {'LineStyle','o','Color',[.3 .6 .6],'LineWidth',2,'MarkerSize',8,'MarkerFaceColor','m'} ;
linstyle_2 = {'Color',[.6 .3 .6],'LineWidth',3} ;
titleprops = {'FontSize',24,'FontWeight','bold',...
    'FontName','FixedWidth','FontAngle','oblique',...
    'Interpreter','None'} ;
axisprops = {'FontSize',20,'FontWeight','normal','FontName','FixedWidth'} ;
ylim_s = [-2 2] ;

% Set up the figure for PNG/JPEG export
canvas = [1 1 2048 1024] ;
fh = figure(1);
set( fh, ...
    'PaperPositionMode','auto', ...
    'Position',canvas ) ;

% Do the plotting and apply styles
ha1 = subplot(2,1,1);
hp11 = plot(t1,f1);
hold on
hp12 = plot(t1,f1);
hold off
title('subplot 1',titleprops{:})
xlabel('t',titleprops{:})
ylabel('f1',titleprops{:})

ha2 = subplot(2,1,2);
hp2 = plot(t2,f2);
title('subplot 2',titleprops{:})
xlabel('t',titleprops{:})
ylabel('f2',titleprops{:})

% finish appliing styles
set(hp11,linstyle_11{:}) ;
set(hp12,linstyle_12{:}) ;
set(hp2,linstyle_2{:}) ;
set(ha1,axisprops{:}) ;
set(ha2,axisprops{:}) ;

% Print
outfname = 'test' ;
print(fh,'-dpng',[outfname,'.png']) ;

% Sometimes it's better to use vector graphics ==>
% alter figure properties to allow proper PDF printouts.
set( fh, ...
        'PaperSize', [29.71 13.01], ...
        'PaperPosition', [0.01 0.01 29.7 13.0] ) ;

% print to pdf file
print(fh,'-dpdf',[outfname,'.pdf']) ;
于 2012-07-09T08:44:28.820 回答
1

尝试使用以下行而不是您已有的打印行。

打印(opslaan,'-dpng','image.png')

另一种选择是调查imwrite.

于 2012-07-05T12:18:27.843 回答