HOW TO INSERT THE DATE (DATETIME) IN THE TITLE?
66 次查看(过去 30 天)
显示 更早的评论
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.
采纳的回答
Image Analyst
2020-12-14
Here's demo to put the date/time of a file, and the current date/time into a caption over an axes.
Adapt as needed, like if you want only the time or only the date. If you can't, then attach your variables in a .mat file.
% Demo to put the date/time of a file, and
% the current date/time into a caption over an axes.
% Specify some file.
fileName = '1.jpg'; % Whatever.
% Get the date of the file.
dirListing = dir(fileName)
% Get the current time.
tNow = datestr(now)
% Create a plot or image or something
imshow(peaks(300), []);
% Create a title
caption = sprintf('File Date = %s. Right now it is %s',...
dirListing.date, tNow);
title(caption, 'FontSize', 12);
更多回答(1 个)
Steven Lord
2020-12-14
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!