How do I save a figure with the same file name as its title within a for loop?

3 vues (au cours des 30 derniers jours)
I've written a code that saves figures within a loop. Currently I have the code
for k = 1:13 % there is some code here to loop through some files
Y = {'Intensity T=10','Intensity T=15','Intensity T=20','Intensity T=25','Intensity T=30','Intensity T=35','Intensity T=40','Intensity T=45','Intensity T=50','Intensity T=55','Intensity T=60','Intensity T=65','Intensity T=70'};
fig1 = figure('name',Y{k},'numbertitle','off');
for ij = 1:6
x = 0:0.2:9.6;
plot(x,fliplr(totalinmodesarray),'k.--');
y = fliplr(intensitymatrix(ij,2:2:end));
intensities{ij} = y;
plot(x,y,'.--')
xlabel('Current (mA)')
ylabel('Power (mW)')
hold on
end
legend('Total','mode 1', 'mode 2', 'mode 3', 'mode 4', 'mode 5', 'mode 6','Location','best')
% some saveas command here
end
This works correctly so that each file is called the corresponding value given in Y{k}. However, I want to be able to save each of the files as its name, after the first loop (where I have commented in the code). How can I get the files to save with this name?

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 11 Déc 2018
saveas(gcf, Y{k}, 'fig')

Plus de réponses (0)

Catégories

En savoir plus sur Printing and Saving dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by