different titles for animation
5 次查看(过去 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
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Title 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!