Solved
C Data Types and Operands
Posted on 2003-12-08
I am actually working in MATLAB/Simulink, however, I need to create my own custom block, and I must use C code inside that block. My problem arises as such...
I read into Matlab a 480x640 matrix of "uint8" data, which I subsequently convert to format "double" (double precision). Simulink reads this matrix in and hands it to my custom C code.
When Simulink reads in the data, I declare it as format "double"...Matlab double. Which gets to the heart of my question. Is Matlab's double the same as C's "double?" I assume that they are, however, I am running into problems.
I have a very simple algorithm which computes the centroid of an object. To do this, I must access the data in the matrix, and in certain instances multiply by integers.
If I simply read the data from the matrix, I have no problems. But when I try to multiply by an integer "i" or "j" (declared as "int" at beginning of code) my answers are way off. I have tried declaring the variables "i" and "j" to "long", "unsigned long," and "double." I have also tried changing the input matrix back to "uint8" data. I get different answers with each combination of formats used.
Thus I am not sure where to go. When I declare the variables "i" and "j" as "double," the compiler tells me that I have
"operands of + have illegal types 'pointer to const double' and 'double'"
I have no idea what this means! Why can't I declare "i" and "j" to be double? FYI, "i" and "j" are variables which point to the current matrix location that I want to look at. They are cycled between 0-479 and 0-679, respectively.
I hope all the info is here. I appreciate any help anyone has to offer.
Thanks,
Matt