How can i change the precision using datenum?
古いコメントを表示
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 件のコメント
Stephen23
2018 年 10 月 29 日
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:
採用された回答
その他の回答 (1 件)
André Fernandes
2018 年 10 月 29 日
編集済み: Stephen23
2018 年 10 月 29 日
6 件のコメント
Stephen23
2018 年 10 月 29 日
@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
2018 年 10 月 29 日
編集済み: Stephen23
2018 年 10 月 29 日
André Fernandes
2018 年 10 月 29 日
"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
2018 年 10 月 29 日
Peter Perkins
2018 年 10 月 31 日
This, from Stephen,
"Use datetime objects and tables to group the data within the required period."
is the correct advice.
カテゴリ
ヘルプ センター および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!