定位在GUI中生成的matlab图形以进行自动保存

时间:2014-06-17 18:00:59

标签: matlab matlab-figure

我一直有一些问题会自动保存在GUI轴面板中绘制的数字。这是我到目前为止的代码:

x= [1 2 3 4 5 6 7 8 9 10];
y = [10 5 6 7 8 20 5 4 3 8];

p = polyfit(x, y, 6);
r = polyval(p, x);

xlabel(handles.axes1, 'Time (\mus)');
ylabel(handles.axes1, 'Angular Velocity (rad/s)');
title(handles.axes1, 'Angular Velocity vs. Time (kT Test)');

aV = plot(handles.axes1, x, y, x, r, 'g--');

%Save figure
ftmp = figure();
copyobj(handles.axes1, ftmp);
set(ftmp, 'units', 'normalized', 'outerposition', [0 0 1 1]);
%Create file name
fileName = ['Test' num2str(time(1)) '_' num2str(time(2)) '_' num2str(time(3))]
saveas(ftmp, fileName, 'png');

图像会自动保存,但不会正确显示。例如,以下是保存的图像:

enter image description here

如您所见,图像非常偏斜。但是,如果我手动保存图像,则整个图形居中并保存。有没有办法在自动保存时重新定位图形? (请注意,我正在寻找不使用export_fig)的解决方案。

我已经搜索了一段时间,但类似问题的答案都没有解决我的问题。

赞赏任何建设性意见。

1 个答案:

答案 0 :(得分:1)

以下是我要做的事情:

x= [1 2 3 4 5 6 7 8 9 10];
y = [10 5 6 7 8 20 5 4 3 8];

p = polyfit(x, y, 6);
r = polyval(p, x);

figure(1);
clf();

plot(x, y, x, r, 'g--');

xlabel('Time (\mus)');
ylabel('Angular Velocity (rad/s)');
title('Angular Velocity vs. Time (kT Test)');

time = clock();
fileName = ['Test' num2str(time(1)) '_' num2str(time(2)) '_' num2str(time(3))]

print('-f1','-dpng', fileName);

不确定你的文件名究竟是什么,所以就像我去的那样。如果您想拥有不同的文件名,则不需要time=clock()

另请注意,您可以使用saveas(1, fileName, 'png');作为最后一行。

相关问题