How can i change the precision using datenum?
Mostrar comentarios más antiguos
Im using datenum on some datasets to try to see the intersection between the data (using intersect function), the problem is that im getting different times with the same time (the last few numbers are a little bit different). I already saw some people using a different aproach but i don't know how can i do it with my data. Im posting the code im using:
horas = datestr(horas);
datas = datestr(datas);
timesteps = [num2str(datas) num2str(horas(:,12:17))];
timesteps = datenum(timesteps,'dd-mmm-yyyy HH:MM');
[c,ia,ib]=intersect(timesteps,time_interval);
hm0(ib) = hm0;
It should work but since it's not getting all the times, it fails and tells me "In an assignment A(:) = B, the number of elements in A and B must be the same.". But if i can solve the early problem it will work since i already used this function before. Thank you
1 comentario
Stephen23
el 29 de Oct. de 2018
To see the real datenum values download James Tursa's FEX submission:
Some useful discussions on floating point numbers:
This is worth reading as well:
Respuesta aceptada
Más respuestas (1)
André Fernandes
el 29 de Oct. de 2018
Editada: Stephen23
el 29 de Oct. de 2018
6 comentarios
Stephen23
el 29 de Oct. de 2018
@André Fernandes: there seems to be a mistake in your logic: you did not explain what hm0 is, or what size it has, but clearly this indexing and allocation
hm0(ib) = hm0
does not work. You should check the index ib and confirm that it has as many unique indices as hm0 has elements.
André Fernandes
el 29 de Oct. de 2018
Editada: Stephen23
el 29 de Oct. de 2018
André Fernandes
el 29 de Oct. de 2018
"I used this to create the time_interval since i thought my data was being measured at the same times every step of the loop, but it's not."
Possibly you should reconsider your approach: if the data are not regular or don't behave as you expect, then you might have to broaden your matching criteria or use a different approach, e.g.:
- Round to the nearest five minutes, or ten minutes, or whatever unit/duration you want (multiply datenum of the time by datenum of that duration, round, divide again by that duration).
- Use datetime objects and tables to group the data within the required period.
- Interpolate the data at regularly spaced sample times.
- etc.
Which to choose depends on your data and how you want to process it.
André Fernandes
el 29 de Oct. de 2018
Peter Perkins
el 31 de Oct. de 2018
This, from Stephen,
"Use datetime objects and tables to group the data within the required period."
is the correct advice.
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!