在 Matlab 中导出具有自定义大小的图形

export figure with customised size in Matlab

图片是想要的尺寸(269*203),但输出的图片太大了。我希望它采用相同的图形大小。

这是我的代码

data=importdata('C:/Users/Eden/Desktop/Acceleration/data.txt');
fig = figure(1);
set(fig, 'Units', 'pixels');
set(fig, 'Position', [0 0 269 203]);
x=data(:,2)
y=data(:,3)
p=plot(x,y)
set(p,'Color','red');
xlabel('Time(milliseconds)','FontSize',12,'FontWeight','bold','Color','b');
ylabel('Acceleration(g unit)','FontSize',12,'FontWeight','bold','Color','b')
saveas(fig,'C:/Users/Eden/Desktop/didi.jpg')

将最后一行替换为:

%tell print to use size of the gui-window
set(fig, 'PaperPositionMode','auto')
%use print because saveas ignores previous line
print('-djpeg','-r100','didi.jpeg')