converting timestamps.npy in matlab

119 views
Skip to first unread message

Judith Schweimer

unread,
Apr 12, 2018, 1:52:50 PM4/12/18
to Open Ephys
Hello,
I have an issue when I convert the timestamps.npy in matlab.

The conversion itself works fine, using the npy to matlab script on GitHub ('https://github.com/kwikteam/npy-matlab').

This produces an array of increasing integers in int64. If I then divide these by the sampling rate, I again get an integer, which is the correct value, but obviously has no decimals being an integer.

Is there a way to convert the int64 into a number that shows the decimals within matlab? I have tried several options like double, but they don't give me the expected value anymore.

Any advice is appreciated,
Judith






Davidson, Tom

unread,
Apr 12, 2018, 2:15:47 PM4/12/18
to Judith Schweimer, Open Ephys
You need to cast the int to double before the division:

timestamp = int64(3000)
samplerate = 30000  % will be of type double by default 

ans1 = timestamp ./ samplerate % returns an int64 with value 0
ans2 = double(timestamp) ./ samplerate % returns a double with value 0.1

% if you convert ans1 to double after the division, the fractional information has already been lost to rounding
double(ans1) % returns a double with value 0


See this page for a discussion of this behavior by Matlab:
"Arithmetic operations that involve both integers and floating-point always result in an integer data type."

Best,
Tom

--
You received this message because you are subscribed to the Google Groups "Open Ephys" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open-ephys+unsubscribe@googlegroups.com.
To post to this group, send email to open-...@googlegroups.com.
Visit this group at https://groups.google.com/group/open-ephys.
To view this discussion on the web visit https://groups.google.com/d/msgid/open-ephys/e7c79b15-b1f3-4a14-9d28-2662220902ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Judith Schweimer

unread,
Apr 13, 2018, 10:48:00 AM4/13/18
to Open Ephys
Thanks, Tom! that worked!

I used a wrong way trying to convert the integers.
Reply all
Reply to author
Forward
0 new messages