Reputation: 9229
I am fairly new to using matrices in C. I have been having some issues in a piece of maths which uses them. To debug, I am trying to check that my matrix is stored correctly and have put the following code in to debug.
float regression_matrix[5][4] = {3.2, -2.8, -0.8, 2.2, -0.8, -3.0, 4.3, 0.9, -3.4, 1.3, 0.9,-1.6,-0.1,2.2,-0.8}; //input the cubic regression values
regression_matrix[1][2] = 12;
float k = regression_matrix[1][2];
pc.printf("Matrix 1,2 %d is %f\r\n", k); // display the ADC Readings
The output is -19.200001, where has this come from? I am not sure if I am just miss-using the printf command or have some issues in setting up my Matrix?
Any ideas would be much appreciated.
Upvotes: 1
Views: 37
Reputation: 20252
Here:
printf("Matrix 1,2 %d is %f\r\n", k);
you have two format specifiers but just one argument. This leads to Undefined Behavior. You probably want
printf("Matrix 1,2 is %f\r\n", k);
Upvotes: 2