How to save multiple figures with specific figure name in a certain directory ?

3 ビュー (過去 30 日間)
SA
SA 2021 年 4 月 20 日
コメント済み: SA 2021 年 4 月 21 日
Hello,
I want to save multiple figures with specific figure name inside a directory. With the following script I've created multiple figures in the Directory but however the figures are saved as .ps format. But I want to save figures as .png with a resolution 1000 or 2000. Can anyone help me to find a solution ? Thank you.
nSensors = size(A,2);
%% Do TimeSeries Analysis with the group of files
for base=1:nSensors
......
....
.....
h=figure;
plot(xx, mn,'r-', 'linewidth', .75); hold on; grid on;
fig_name = strcat('Pulse_of_Sensor_Gr_',num2str(base)); %% exportgraphics(gcf, sprintf('Fig_%d.png', k)); % Or gca instead of gcf.
title(sprintf ('[1-100]-th Files Avg. 1sec Pulse:"MAX" Sensor-%d', base));
xlabel(sprintf('Time'));
ylabel('Magnitude after thresholding');
set(gcf, 'PaperUnits','inches','PaperPosition',[0 0 3.3 2]);
ax = gca; ax.FontSize = 8; %ax.FontWeight = 'bold';
destination='C:\Users\sys\Max\Figures\';
print([destination,num2str(base),'-dpng','-r2000']);
close(h)
end
  2 件のコメント
Jan
Jan 2021 年 4 月 20 日
"the figures are saved as .ps format" - why do you assume this? print -dpng creates PNG files, so maybe you are looking into the wrong folder?
SA
SA 2021 年 4 月 21 日
Thank you for the response. If I use this command
print([destination,num2str(base),'-dpng','-r2000']);
then I get the file names like these 'h1-dpng-r2000.ps' , 'h2-dpng-r2000.ps'........and so on here these names does not reflect the 'fig_name'. When I use this command
print([destination,fig_name,'-dpng','-r2000']);
then I get 'hCEB_Pulse_of_Sensor_Gr_1-dpng-r2000.ps', 'hCEB_Pulse_of_Sensor_Gr_2-dpng-r2000.ps'.............and so on. I don't understand why Matlab consider '-dpng' as figure names rather '-dpng' as figure types. Can you point out what's wrong here? Thanks again.

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

採用された回答

Jan
Jan 2021 年 4 月 21 日
編集済み: Jan 2021 年 4 月 21 日
Ah, I see:
print([destination,num2str(base),'-dpng','-r2000']);
% ^ End of file name ?!
% Better:
print([destination, num2str(base)], '-dpng', '-r2000');
% ^ File name ends here
  1 件のコメント
SA
SA 2021 年 4 月 21 日
Many thanks to you. It works fine as of my expectation.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by