HOW TO INSERT THE DATE (DATETIME) IN THE TITLE?
66 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
DUMITRU ROBERT GUGIU
el 14 de Dic. de 2020
Comentada: Image Analyst
el 22 de Jul. de 2023
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 comentarios
Walter Roberson
el 14 de Dic. de 2020
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
el 14 de Dic. de 2020
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.
Respuesta aceptada
Image Analyst
el 14 de Dic. de 2020
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);
Más respuestas (1)
Steven Lord
el 14 de Dic. de 2020
peaks
title("It is currently " + string(datetime('now')))
2 comentarios
Brian Whatcott
el 21 de Jul. de 2023
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
el 22 de Jul. de 2023
@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.
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!