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

3 ビュー (過去 30 日間)
JJH
JJH 2018 年 12 月 11 日
回答済み: Fangjun Jiang 2018 年 12 月 11 日
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 Center および File ExchangePrinting and Saving についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by