Storing binary data in stimulus announcements

Najib Majaj's Avatar

Najib Majaj

15 Oct, 2015 01:36 PM

romesh is trying to replicate what you do with dots (outputting the x/y locations of every dot).
he noticed that you are stringing them along with no comma or delimiters. How do you then parse them out? Or are the number always a certain number of digits?


  1. Support Staff 1 Posted by Christopher Sta... on 15 Oct, 2015 03:18 PM

    Christopher Stawarz's Avatar

    Hi Najib,

    I assume you're referring to this line from MovingDots.cpp:

    Datum dotsData(reinterpret_cast<char *>(&(dotPositions[0])), dotPositions.size() * sizeof(GLfloat));

    The key point is that I'm not converting anything to a string. Rather, I'm taking the raw bytes from the dotPositions vector, casting them to char * (without modifying the data in any way), and then creating a string-typed Datum from them. This is taking advantage of the facts that a char holds one byte, and that basic C/C++ strings (and hence MWorks strings) are stored without any awareness of character encoding. Ultimately, the position data is not a string, and it would look very weird if you tried to print it out.

    To see how to unpack the position data from an event file, have a look at validateDotsData.m (or the Python equivalent, In both cases, you take the bytes of the "string" and cast them to a single-precision floating-point array.


  2. Christopher Stawarz closed this discussion on 21 Oct, 2015 02:09 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

17 May, 2022 02:12 PM
16 May, 2022 03:12 PM
04 May, 2022 06:02 PM
03 May, 2022 01:30 PM
02 May, 2022 10:47 PM