How can convert two (file.fig) to (file.jpg) in the same time?

2 ビュー (過去 30 日間)
Riyadh Muttaleb
Riyadh Muttaleb 2016 年 12 月 21 日
コメント済み: Jan 2017 年 1 月 26 日
Hello All,
I would like to convert (file.fig) to (file.jpg) in the same time (each file contents 5 plots) to reduce the time. I used this code to convert one file.fig:
figs = openfig('Fall_ABS.fig');
for K = 1 : length(figs)
filename = sprintf('figure_%02d.jpg', K);
saveas(figs(K), filename);
end
close all
How can I update this code to convert two files.
Thanks in advance,
Riyadh

採用された回答

John BG
John BG 2016 年 12 月 22 日
編集済み: John BG 2016 年 12 月 25 日
put all figures to translate to .jpg in a same folder
put all .fig in same folder
cd 'folder_figures'
get in the folder
system('dir /o:n /b > list.txt')
build list
fid=fopen('list.txt')
s1=textscan(fid,'%s')
fclose(fid)
measure how many figures
[sz1 sz2]=size(s1{1})
load all figures in workspace
h0=[];
for k=1:1:sz1
if regexp(cell2mat(s1{1}(k)),'.fig')
s=openfig(cell2mat(s1{1}(k)));
h0=[h0 s];
end;
end;
save figures in same file
savefig(h0,'all_figures.fig')
Riyahd, do the figure handles have to be in separate variables, or is it ok that all such handles are in a 1x10 vector of handles?
if you find my answer useful would you please mark it as Accepted Answer by clicking on the ACCEPT ANSWER button?
thanks in advance for time and attention
John BG
  3 件のコメント
John BG
John BG 2016 年 12 月 27 日
have you received the files I sent you?
Jan
Jan 2017 年 1 月 16 日
編集済み: Jan 2017 年 1 月 16 日
Using system('dir /o:n /b > list.txt') instead of Matlab's dir command is much slower and prone to errors. The current folder is polluted by a "list.txt" file and if several codes run simultaneously (e.g. in timer oder GUI callbacks) theses files can interfere.

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2017 年 1 月 17 日
folder = cd; % Set accordingly
figs = dir(fullfile(folder, '*.fig'));
for K = 1:length(figs)
FigH = openfig(fullfile(folder, figs(K).name));
filename = fullfile(folder, sprintf('figure_%02d.jpg', K));
saveas(FigH, filename);
close(FigH);
end
  2 件のコメント
Riyadh Muttaleb
Riyadh Muttaleb 2017 年 1 月 19 日
Thank you for your answer, What does first step mean?
Jan
Jan 2017 年 1 月 26 日
Do you mean "folder = cd"? This means that the variable "folder" should be set to the folder your images are stored in. Using absolute paths is safer than relying on the current folder.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by