How to save figures from a loop to current folder with specific names

1 次查看(过去 30 天)
My Code shows 9 figures ( T=1:3 and b=1:3) in a loop and it saves in my current folder. But it saves as:
  • T1.pngT1
  • T1.pngT2
  • T1.pngT3
  • T2.pngT1
  • T2.pngT2
  • T2.pngT3... and so on
But I have 2 variables, so I want to to save them as:
  • T1b1
  • T1b2
  • T1b3
  • T2b1
  • T2b2
  • T2b3.... and so on
How can I do this?
clear all;
clf
n=100;
t0 = 0.5;
T = 1:3;
b = 1:3;
for v_T = 1:length(T)
for v_b = 1:length(b)
T_A = T(v_T)
b_A = b(v_b)
pdf2p = @(x) (b_A/T_A).*(x/T_A).^(b_A-1).*(exp(-(x/T_A).^(b_A)));
pdf3p = @(x) (x>t0).*(b_A/(T_A-t0)).*((x-t0)/(T_A-t0)).^(b_A-1).*(exp(-((x-t0)/(T_A-t0)).^(b_A)));
h= figure
fplot(pdf2p,[0,10], 'LineWidth',2, "Color", 'b')
hold on
fplot(pdf3p,[0,10], 'LineWidth',2, "Color", 'r', 'LineStyle', '--')
ax = gca;
ax.XLim=[0,2.5];
ax.YLim=[0,3];
grid on; %Gitter anzeigen
box on; %Rahmen zeigen
title ('2- und 3 parametrische Dichtefunktion für n=10');
xlabel('Lebensdauer t');
ylabel('Dichtefunktion f(x)');
legend(['T=' num2str(T_A), ', b=' num2str(b_A)], ['T=' num2str(T_A), ', b=' num2str(b_A), ', t0=' num2str(0.5)])
saveas(h,sprintf('T%d.png',T_A, b_A))
end
end

采纳的回答

Ameer Hamza
Ameer Hamza 2020-9-23
编辑:Ameer Hamza 2020-9-23
Write saveas() line like this
saveas(h, sprintf('T%db%d.png',T_A, b_A))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by