フィルターのクリア

How to split time in to hours, minutes and nanoseconds

7 ビュー (過去 30 日間)
Mantas Vaitonis
Mantas Vaitonis 2018 年 11 月 15 日
コメント済み: madhan ravi 2018 年 11 月 15 日
Hello,
I would like to split my timserias in order to convert them to to nanoseconds, what I have so far is:
t = ('16:45:00.103450009');
tt=str2double(strsplit(t,':'));
But double shows only four numbers after decimal point, what would be the way to achieve this?

採用された回答

madhan ravi
madhan ravi 2018 年 11 月 15 日
編集済み: madhan ravi 2018 年 11 月 15 日
see format and adapt whatever is suitable for you
format long g %at the very beginning
  4 件のコメント
Guillaume
Guillaume 2018 年 11 月 15 日
As explained in the documentation of format,
  • long: Long, fixed-decimal format with 15 digits after the decimal point for double values, and 7 digits after the decimal point for single values
  • longG: Long, fixed-decimal format or scientific notation, whichever is more compact, with a total of 15 digits fordouble values, and 7 digits for single values.
The difference is actually obvious:
>> format long
>> 3.14
ans =
3.140000000000000
>> 1e28
ans =
1.000000000000000e+28
>> [3.14 1e28]
ans =
1.0e+28 *
0.000000000000000 1.000000000000000
>> format longg
>> 3.14
ans =
3.14
>> 1e28
ans =
1e+28
>> [3.14 1e28]
ans =
3.14 1e+28
I find long completely useless (see last example where pi is reduced to 0). I only ever use longg or shortg
madhan ravi
madhan ravi 2018 年 11 月 15 日
Thank you very much Guillame for the beautiful explanation

サインインしてコメントする。

その他の回答 (1 件)

Luna
Luna 2018 年 11 月 15 日
Hi,
Run this code
format long
then run your tt you will see long format in your command window.

カテゴリ

Help Center および File ExchangeLanguage Fundamentals についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by