different titles for animation

7 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Title 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by