フィルターのクリア

How to change the plot title and file name when saving it to a for loop

6 ビュー (過去 30 日間)
Richard Wood
Richard Wood 2020 年 6 月 25 日
回答済み: the cyclist 2020 年 6 月 25 日
Hello everyone
I have the following arrays of relevance to the question:
substrates=["MgO" "SiO2" "W"];
substrates_title=["MgO" "SiO$_2$" "W"];
which I want to be introduced in the title of a plot and in the name of the file that encapsulates the aforementioned plot in a for loop. For that, I have written preliminarily the following lines related to this:
t1=title(['Thermal background $T=\,$',num2str(Temperature(i)),' K, ',substrates_title(l),''],'FontSize',14,'interpreter','latex')
...
saveas(gcf,fullfile(outputdir,['Scaling_Based_Temperature_Dependent_Phase_Diagram_Thermal_Background_T=',num2str(Temperature(i)),'_K_with_Joule_Heating_',substrates(l),'_Substrate.pdf']))
but this does not work, exceptly the num2str(Temperature(i)) that works perfectly.
Any suggestion?

採用された回答

the cyclist
the cyclist 2020 年 6 月 25 日
Part of the problem is that you are mixing character arrays and strings. The following works (after you set your own outputdir):
i = 1;
l = 1;
Temperature(i) = 273.15;
outputdir = 'SET ME TO WHAT YOU WANT!!';
substrates={'MgO' 'SiO2' 'W'};
substrates_title={'MgO' 'SiO$_2$' 'W'};
t1=title(['Thermal background $T=\,$',num2str(Temperature(i)),' K, ',substrates_title{l},''],'FontSize',14,'interpreter','latex')
fname = ['Scaling_Based_Temperature_Dependent_Phase_Diagram_Thermal_Background_T=',num2str(Temperature(i)),'_K_with_Joule_Heating_',substrates{l},'_Substrate.pdf'];
saveas(gcf,fullfile(outputdir,fname));
Note that I used a cell array of character arrays, rather than strings. One could probably have done the opposite.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTitle についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by