Reformat the date and time, and also show nanoseconds using mathlab

조회 수: 12 (최근 30일)
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

채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 21일
You need to tell us more about the data representation.
Are these value serial date numbers? If so then
>> eps(now)
ans =
1.16415321826935e-10
>> ans * 24*60*60
ans =
1.00582838058472e-05
which tells you that you cannot get higher resolution than 1000 nanoseconds using that format.
If you are trying to time events using tic and toc, then you will find that those clocks are only defined down to milliseconds (1000 Hz). To go beyond that requires system-dependent methods.
  댓글 수: 4
Paskah Nainggolan
Paskah Nainggolan 2011년 3월 22일
I'm looking for how matlab can find the time to nano-second?
The following code that I created but can not make time to nano..
function Tx_send_Callback(hObject, eventdata, handles)
TxText = get(handles.Tx_send, 'string');
fprintf(handles.serConn, TxText);
currList = get(handles.history_box, 'String');
set(handles.history_box, 'String', ...
[currList ; ['Sent = ' date(now) ': ' TxText] ]);
set(handles.history_box, 'Value', length(currList) + 1 );
set(hObject, 'String', '');
Walter Roberson
Walter Roberson 2011년 3월 31일
Mathworks does not provide any means to time serial device events to nanoseconds. If you had the Data Acquisition Toolbox and were receiving the data with an appropriate card, you might be able to get access to higher resolution time stamps; I do not know how accurate they can go.
Recall that a nanosecond only about 2 clock cycles on a 2 GHz CPU. There is no way that an interpreted language such as MATLAB running on a multiprocessing system is going to be able to reliably interrupt and access hardware clock cycle counters within 2 instructions. For nanosecond measurements, you need a real-time device or additional hardware support.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

James Tursa
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
Paskah Nainggolan
Paskah Nainggolan 2011년 3월 31일
n = now;
while( true )
m = now;
if( m ~= n )
disp((m-n)*86400);
n = m;
end
end
how to see the difference time in orde nano seconds from the program?
Walter Roberson
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
Paskah Nainggolan 2011년 3월 31일
how i can get the compiler openMP
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 3월 31일
That is a new question on a different topic; please start a new thread.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile 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!

Translated by