フィルターのクリア

different titles for animation

5 ビュー (過去 30 日間)
Nahid Atashi
Nahid Atashi 2019 年 7 月 23 日
コメント済み: Nahid Atashi 2019 年 7 月 23 日
Hi friends,
I have a code to make an animation which is fine and works but i need to creat title for each map
in this animation. I tried but couldn't make it as a loop.
Maps are monthly for 40 years from 1979:2018. the titles should be like: {'Jan 1979', 'Feb 1979',.................'Dec 1979', 'Jan 1980'.........}
and so on (12 month for each year).
could some body help me please?
thanks in advance
This is the main part of the code:
%% creat animat
for i=1:12
a=reshape(monthly(i,:),81,65);
a(~inMap)=nan;
for k=1:12
[c,h]=contourf(XX,YY,a ,'LineStyle','none');colorbar;
hold on
plot(lonos(:,1),latos(:,1),'black');
title (sprintf('% JAN 1979',k));
pause(1)
% input('-->','s');
end
end

採用された回答

David K.
David K. 2019 年 7 月 23 日
I would suggest creating the title like this:
months = {'Jan', 'Feb', ...};
years = num2str((1979:2018)');
for i = 1:40
for k = 1:12
title(strcat(months{k}," ",years(i,:)));
end
strcat is a string concatenation -> It puts the strings together. I assumed the outer loop is meant to be years so I changed it from 12 to 40 since you mentioned 40 years.
-Also note, it is highly recommended that you do not use i as a variable. It is the built in constant for the imaginary number.
  1 件のコメント
Nahid Atashi
Nahid Atashi 2019 年 7 月 23 日
thanks so much David for your great answer. it works perfectly.

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

その他の回答 (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