Storing binary data in stimulus announcements

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?

best
najib

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, validate_dots_data.py). In both cases, you take the bytes of the “string” and cast them to a single-precision floating-point array.

Cheers,
Chris