Add data tips at specific date time
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lauren
el 10 de Dic. de 2025 a las 22:20
Comentada: Walter Roberson
el 11 de Dic. de 2025 a las 1:05
I am trying to add datatips at a specific time in my data
a is datetime
b is temperature
I would like to add datatip on b at nearest YYYY-MM-DD HH:MM using datatip().
Thanks in advance.
0 comentarios
Respuestas (1)
Les Beckham
el 10 de Dic. de 2025 a las 23:04
It's always useful to provide some sample data for questions like this. I'll make up some data for now.
Hopefully this example will help will show you what to do to get what you want with your actual data.
a = datetime('now') + duration(0, [0:120], 0, 0); % Make up some test data
b = linspace(0, 10, numel(a)) + rand(1, numel(a));
hl = plot(a,b);
grid on
xlabel 'Time'
ylabel 'Temperature'
% pick a time point an hour from now for testing - replace with your
% desired time
desired_time = datetime('now') + hours(1);
temp_at_desired_time = b(find(a>desired_time, 1));
datatip(hl, desired_time, temp_at_desired_time);
1 comentario
Walter Roberson
el 11 de Dic. de 2025 a las 1:05
temp_at_desired_time = b(find(a>desired_time, 1));
There is another way to achieve this, that is slightly longer but is good in the case of finding the right location for several times
temp_at_desired_time = interp1(a, b, desired_time, 'previous');
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!
