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

1 view (last 30 days)
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

Accepted Answer

Ameer Hamza
Ameer Hamza on 23 Sep 2020
Edited: Ameer Hamza on 23 Sep 2020
Write saveas() line like this
saveas(h, sprintf('T%db%d.png',T_A, b_A))

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!