Variably assigning names to graphs created in a loop
조회 수: 6 (최근 30일)
이전 댓글 표시
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
채택된 답변
the cyclist
2015년 5월 6일
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
추가 답변 (2개)
Guillaume
2015년 5월 6일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Labels and Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!