Reformat the date and time, and also show nanoseconds using mathlab
이전 댓글 표시
I made a program about the moving object distance calculation,I have problem in finding time to receive and send the difference to be precise in order of nano, how to find the mathlab retrieve data with nanosecond.thx
채택된 답변
추가 답변 (2개)
James Tursa
2011년 3월 22일
The "now" function is only good to about 0.015 sec accuracy. You should not use it for any timing that you need more precisely than that. e.g., run this code (Ctrl-C to stop it):
n = now;
while( true )
m = now;
if( m ~= n )
disp((m-n)*86400);
n = m;
end
end
You will have to get more precise timing some other way. e.g., if you have an OpenMP capable compiler you could get MTIMESX from the FEX and use its omp_get_wtime functionality. e.g.,
n = mtimesx('omp_get_wtime');
while( true )
m = mtimesx('omp_get_wtime');
if( m ~= n )
disp(m-n);
n = m;
end
end
On my system the above returns differences on the order of 1.5e-5 seconds (I presume this is all system dependent), so maybe something like this will work for you. MTIMESX (which admittedly is overkill for your situation) can be found here:
댓글 수: 3
James Tursa
2011년 3월 22일
Note that eps(now)*86400, which gives a result in the 1e-5 range, is misleading. The "now" function is *not* that accurate as the above test code will show you.
Paskah Nainggolan
2011년 3월 31일
Walter Roberson
2011년 3월 31일
You could multiply the difference by 10^9, but as discussed above that number not be meaningful to within 15000 nanoseconds.
Paskah Nainggolan
2011년 3월 31일
0 개 추천
댓글 수: 1
Walter Roberson
2011년 3월 31일
That is a new question on a different topic; please start a new thread.
카테고리
도움말 센터 및 File Exchange에서 Data Acquisition Toolbox Supported Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!