Placing a title for multiple plots in a for loop

I have a for loop that will generate a bunch of plots, say 50. I want to put a title on each one but I don't want to do this 50 times if I can avoid it. I want the titles to be "Test A at 0 mins", "Test A at 5 mins", "Test A at 10 mins" and so forth. Is there a way where I can just type in "Test A at" and MATLAB can fill out the time as it goes through the for loop?

 採用された回答

Ben11
Ben11 2014 年 7 月 9 日
編集済み: Ben11 2014 年 7 月 9 日

0 投票

You can use sprintf to format the title within the loop, for instance you could store all your title in a cell array for future reference, but in a loop that would look like this:
TitleArray = cell(1,50);
for i = 1:50
A{i} = sprintf('Test A at %i mins\n',i);
end
Of course you could just put the title after you draw the plot:
hold all
for i =1:50
...you code for generating the plots
title(sprintf('Test A at %i mins\n',i));
end
hold off
Do you want to generate 50 plots in the same figure or all on one big figure?

2 件のコメント

Hail
Hail 2014 年 7 月 9 日
AWESOME! THANK YOU!!!
Ben11
Ben11 2014 年 7 月 9 日
Great you're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2014 年 7 月 9 日

コメント済み:

2014 年 7 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by