I added an assignment to 0 of a particular variable as a way of indicating where in the data stream a protocol actually started. This caused a strange behavior where every value after that was recorded as an int64, even though it was being set to float values. If I use a float value (-0.1 specifically), this doesn’t happen. I can provide code to reproduce if that will help.
Hi Evan,
I can provide code to reproduce if that will help.
Yes, I’ll need some, as I haven’t been able to reproduce this issue myself. If possible, please send me both an MWorks experiment and (if applicable) a MATLAB script that manifest the problem.
Thanks,
Chris
Hi Evan,
Thanks for the example code and data files. The issue is in the last line of your MATLAB script:
responseDur = [responseDurEvents(:).data];
You’re asking MATLAB to create a numeric array from the elements of a struct array. Apparently, the presence of a single int64 value in the input causes MATLAB to make the entire output array int64.
One workaround is to create a cell array instead:
responseDur = {responseDurEvents(:).data};
You can then use cell indexing to extract the individual values:
>> responseDur{4}
ans =
0
>> responseDur{5}
ans =
0.6661
This does make me ask (once again) whether it does more harm than good for getEvents to return int64 values. The possibility of losing precision when converting from int64 to double bothers me, although I doubt it would matter much in practice. The cost of not converting is that you run into all these cases where MATLAB behaves in unexpected ways in the presence of non-double values.
Do you have any thoughts on this?
Chris
I see. I was mistaken in thinking that MWorks was actually saving all the values as int64. Because that isn’t the case, this isn’t really a problem.
I don’t think I’ll ever use int64 values from MWorks, but I’m definitely not going to say to get rid of them entirely because I don’t know whether other people use them.
Thanks!