Variably assigning names to graphs created in a loop
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Carolin Brueckmann
il 6 Mag 2015
Commentato: Guillaume
il 6 Mag 2015
Hi there,
I am trying to produce 19 plots for different time series and have Matlab assign them names according to an index. With my code I achieve to name the 19 graphs according to the number i (so 1,2,..,19), but I would like to have the names of the index given to the current i (so if i is 3 in the current run the name of the graph should be HYB).
Index = 1; % 1 = BarclaysUSCreditBondIndex, 2 = Hjrentelande, 3 = HYB, 4 = Ink1Y, 5 = Ink3Y, 6 = KFX, 7 = MSCIEmergingMarkets, 8 = MSCIEuropa, 9 = MSCIFjernstenexJapan, 10 = MSCIJapan, 11 = MSCIUSA, 12 = Real3Y, 13 = Real5Y, 14 = Real7Y, 15 = Stat2Y, 16 = Stat3Y, 17 = Stat5Y, 18 = Stat7Y, 19 = Virkobl
nIndices=3
for i=1:nIndices
figure
plot(Date(2:end), returns(:,i))
datetick('x')
xlabel('Date')
ylabel('Return')
title(sprintf(' %d' ,i))
end
I would appreciate any Tips!
Thanks in advance.
Carolin
0 Commenti
Risposta accettata
the cyclist
il 6 Mag 2015
Here is how I usually do that:
IndexList = {'BarclaysUSCreditBondIndex','Hjrentelande','HYB'};
nIndices = numel(IndexList)
for i = nIndices
figure
plot(rand(5))
title(['This is the plot for index ',IndexList{i}])
end
0 Commenti
Più risposte (2)
Guillaume
il 6 Mag 2015
Simply use a cell array for the graph names:
graphnames = {'BarclaysUSCreditBondIndex', 'Hjrentelande', 'HYB', 'Ink1Y', 'Ink3Y', ...
'KFX', 'MSCIEmergingMarkets', 'MSCIEuropa', 'MSCIFjernstenexJapan', ...
'MSCIJapan', 'MSCIUSA', 'Real3Y', 'Real5Y', 'Real7Y', 'Stat2Y', ...
'Stat3Y', 'Stat5Y', 'Stat7Y', 'Virkobl'};
for graph = 1:nindices
%... plot graph
title(graphnames{graph});
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Labels and Annotations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!