HOW TO INSERT THE DATE (DATETIME) IN THE TITLE?
古いコメントを表示
clear all; clc;
%% parte dedicata a lettura dati
ncfile='corrente1.nc';
ncinfo(ncfile);
ncdisp(ncfile);
x1=ncread(ncfile,'lon');
y1=ncread(ncfile,'lat');
time= ncread(ncfile,'time');
time1=(time*60)-(2208988800') ;
date_matlab = datetime (time1, 'convertfrom','posixtime');
formatOut = 'ddmmyyyy';
tt=datestr(date_matlab,formatOut);
io=num2str(tt)
figure
for t=1
startLoc = [1 1 1 t];
count = [Inf Inf 1 1];
d = ncread(ncfile,'uo',startLoc,count);
d=d';
startLoc = [1 1 1 t];
count = [Inf Inf 1 1];
r = ncread(ncfile,'vo',startLoc,count);
r=r';
clf
rob=((d.^2)+(r.^2)).^(1/2);
mymap=pcolor(x1,y1,rob)
mymap.EdgeAlpha=0
hold on
load coast
plot(long,lat+0.1,'black')
q=quiver(x1,y1,d,r,100,'black')
c=q.AutoScaleFactor
q.AutoScaleFactor=1.8
c=q.MaxHeadSize
q.MaxHeadSize=100
sr=colorbar
caxis([0 0.3])
sr.Label.String = 'm/s';
xlabel('longitudine')
ylabel('latitudine')
title(num2str(time(t)))
%print(['tempesta 28072019 [m s^-1] ' num2str(time(t)) '.png'],'-dpng');
VALOREMASSIMO=max(max(r))
end
2 件のコメント
Walter Roberson
2020 年 12 月 14 日
formatOut = 'ddmmyyyy';
tt=datestr(date_matlab,formatOut);
io=num2str(tt)
You do not use io after that point, so you should not assign to it.
Once you have removed that assignment, you will not be using tt after the assignment to it, so remove that line too.
Once you have done that, you will not be using formatOut anywhere, so delete that too.
In other words, delete all three of those lines; you do not need them.
Walter Roberson
2020 年 12 月 14 日
title(num2str(time(t)))
I believe what you should be using instead is
title(string(date_matlab(t)))
You can set the Format property of date_matlab to reflect the output format you want -- probably 'ddMMyyyy' if it is to be the same format you were using for tt . Caution: datestr() uses mm for months but datetime() uses MM for months.
採用された回答
その他の回答 (1 件)
peaks
title("It is currently " + string(datetime('now')))
2 件のコメント
Brian Whatcott
2023 年 7 月 21 日
I want you to know that to a person who has spent several hours attempting to place a passed name and the current date and time in a title, your offering comes as a cool draft to a desert traveller. Thank you. O Lord!
Image Analyst
2023 年 7 月 22 日
@Brian Whatcott like I showed in my answer, you can use sprintf() to make up virtually any title/caption for your axes that you want.
% Create a title
caption = sprintf('File Date = %s. Right now it is %s',...
dirListing.date, tNow);
title(caption, 'FontSize', 12);
You can put whatever variable values in that you want.
カテゴリ
ヘルプ センター および File Exchange で Title についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

