【发布时间】:2016-06-05 03:27:14
【问题描述】:
我有一个目录中的.fig 文件列表。
如何编写一个简单的matlab函数,自动将所有.fig文件转换为.jpg文件?
【问题讨论】:
-
阅读手册!有打开图的功能,也有保存图的功能。
-
我强烈建议将 matlab 图形保存到
.png而不是.jpg。jpg压缩会导致您的身材出现很多锯齿,而.png文件不会出现这种情况。
我有一个目录中的.fig 文件列表。
如何编写一个简单的matlab函数,自动将所有.fig文件转换为.jpg文件?
【问题讨论】:
.png 而不是 .jpg。 jpg 压缩会导致您的身材出现很多锯齿,而 .png 文件不会出现这种情况。
Matlab 无花果只是您必须加载到 Matlab 中以进行解释和转换的矩阵,因此您可以尝试以下操作:
fig=openfig(FileName,'new','invisible');
saveas(fig,OutputFileName.jpg,'jpg')
close(fig);
“不可见”选项不会在绘图中打开无花果,因此可以节省内存和时间。
【讨论】:
GameOfThrows 的回答有助于将单个 .fig 文件保存到 .jpg
要遍历所有 .fig 文件,这对我有用:
//obtain the files with .fig extension
files = dir('*.fig');
//loop through the .fig files
for i=1:length(files)
//obtain the filename of the .fig file
filename = files(i).name;
//open the figure without plotting it
fig = openfig(filename, 'new', 'invisible');
//save the figure as a jpg
saveas(fig, 'example.jpg');
//close the figure so that the next could be opened without some java problem
close;
end
【讨论】: