MATLAB Bug
Update
Richard Southern has found that if you set the rotInd variable twice in a row, then the bug disappears. He was using MATLAB 7.3. I’ve made his modification available here.
Problem in MATLAB 7.4 JIT Optimizer?
Yi Li pointed out a problem with my MOCAP toolbox 0.135 when used with Matlab 7.4. A little investigation revealed an unusual bug in MATLAB.
To recreate this you need to download the MOCAP toolbox vrs 0.135 and the NDLUTIL toolbox vrs 0.16. They are available from here and here. I used MATLAB Version 7.4.0.336. I couldn’t recreate the bug in vrs 7.0.1.24704. The bug occurred regardless of whether I was using the JVM.
>> version
ans =
7.4.0.336 (R2007a)
>> [skel, channels, frameLength] = bvhReadFile('examples/Swagger.bvh');
>> skel.tree(1).rotInd
ans =
5 6 0
>>
In MATLAB 7.0, the same commands produce this:
>> version
ans =
7.0.1.24704 (R14) Service Pack 1
>> [skel, channels, frameLength] = bvhReadFile('examples/Swagger.bvh');
>> skel.tree(1).rotInd
ans =
5 6 4
>>
The difference is that the last element of the vector is zero in 7.4 and four in 7.0. So I thought I’d do a little debugging in 7.4 to see if the format of some functions had changed. So I ran
>> version
ans =
7.4.0.336 (R2007a)
>> dbstop at 120 in bvhReadFile
>> [skel, channels, frameLength] = bvhReadFile('examples/Swagger.bvh');
120 skel.tree(jointNo).posInd(1, 3) = channelNo + i;
K>> dbcont
>> skel.tree(1).rotInd
ans =
5 6 4
>>
and the problem disappeared. One possible explanation is that there is a problem with the JIT optimizer in MATLAB 7.4, and the optimizer is switched off when you debug. It seems like a pretty major bug.