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

3 次查看(过去 30 天)
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?

采纳的回答

Fangjun Jiang
Fangjun Jiang 2018-12-11
saveas(gcf, Y{k}, 'fig')

更多回答(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