"Kate J." wrote in message <jh99np$9fl$
1...@newscl01ah.mathworks.com>...
> I apologize if this isn’t really a question that should be posted on the Mathworks forum, but I have some Matlab m-code that involves a lot of matrix operations, which I had to convert to C code. I’m hoping that there is someone on this forum who has both Matlab and C expertise. I’ve reviewed my code’s logic numerous times, and can’t yet find the logical flaw that’s preventing my C code from matching my m-file’s values.
>
> Here’s a description of the code, and of the bug:
>
> ~ the Matlab code multiplies the output of the calls to trans_axis() (output = 4x4 matrix of doubles), by the goalTM or actualTM matrices, which are also 4x4. The result is updated values for the 4x4 goalTM and actualTM matrices.
>
> ~ my C code seeks to reproduce the Matlab functionality. Since I didn’t think that it would be a good idea to call
> MatrixMult(goalTM, TM1, goalTM);
>
> … because it might result in overwriting the goalTM values that are the inputs to the function, I instead use a temporary 4x4 array named out1[][], into which the MatrixMult() function’s outputs are copied. I then copy the out1[][] values back into the goalTM[][] array, before the for loop executes again.
>
>
>
> Here’s the original m-code:
>
> for j=1:5
> goalTM=goalTM*trans_axis(rotaxis(j,1),goal_angles(j),translation(j,1));
> end
Please post all of the relevant m-code for us to see. How, exactly, is MatrixMult called in your code? What, exactly, does MatrixMult do? Etc.
> ---------------------------------------------------
>
> My C code:
>
> for(j = 0; j < 5; j++){
>
> /* call trans_axis() function, which writes output values into the TM1 array */
> /* note: I have confirmed that trans_axis() is working properly and passes back the correct TM1 output matrix */
>
> trans_axis(rotaxis[j][0],goal_angles[j],translation[j][0],TM1);
>
> /* multiply the current goalTM[4][4] matrix by the TM1[4][4] matrix, and return out1[4][4] matrix */
> MatrixMult(goalTM, TM1, out1);
Can you post your MatrixMult C-code?
> /* PROBLEM: the *first* out1[4][4] value is correct (showing that the MatrixMult() function is working properly), but the 2nd and subsequent out1 matrices are incorrect, indicating that there's some problem in the management of the variables... */
>
> /* copy the output matrices back into the goalTM array */
> for(a = 0; a < 4; a++){
> for(b = 0; b < 4; b++){
> goalTM[a][b] = out1[a][b];
> }
> }
>
> } /* end for(j…) loop */
Are all of your matrix declarations the same?
> Can anyone spot the logical flaw in my translation of Matlab code into C code? To restate the bug/problem, I get the correct result from the *first* call to MatrixMult(), but then the out1[][] output of the *second*, and all subsequent, calls to MatrixMult() are incorrect. Thanks in advance for your insights.
Once you post more of your code we can comment on where the error(s) might be.
James Tursa