I am trying to run example provided by field II on my computer. This example contains matlab functions as well as mex32 file. I have later version of matlab so i take initial .c file and converted it into mex64. However despite setting everything like in provided example my mex function does not work. I am not that familiar with c programming so i am not sure where exacly in the main function problem occurs. If anyone please could direct me what is going wrong in this .c program. Also, can i succesfully transform this c code to matlab function instead of using mex file or is there some nuances in the C code that can not be fully captured in the MATLAB translation?
Matlab error full original C code
I was trying to write matlab function based on algorithm from C program but i am not sure if i am getting indexing correctly. I am aware that matlab indices starts from 1 not 0. What i don't understand is this env_pointer being set to be one variable's address and then is called like it contains N_samples+1 variables.
void make_interpolation (unsigned char *envelope_data, /* The envelope detected and log-compressed data */
int N_samples, /* Number of samples in one envelope line */
int *index_samp_line, /* Index for the data sample number */
int *image_index, /* Index for the image matrix */
float *weight_coef, /* The weight table */
int N_values, /* Number of values to calculate in the image */
unsigned char *image) /* The resulting image */
{int i; /* Integer loop counter */
int ij_index_coef; /* Index into coefficient array */
unsigned char *env_pointer; /* Pointer to the envelope data */
float *weight_pointer; /* Pointer to the weight coefficients */
ij_index_coef = 0;
for (i=0; i<N_values; i++)
{
weight_pointer = &(weight_coef[ij_index_coef]);
env_pointer = &(envelope_data[index_samp_line[i]]);
image[image_index[i]]
= weight_pointer[0] * env_pointer[0]
+ weight_pointer[1] * env_pointer[1]
+ weight_pointer[2] * env_pointer[N_samples]
+ weight_pointer[3] * env_pointer[N_samples+1] + 0.5;
ij_index_coef = ij_index_coef + 4;
}
}
At first glance this is the obvious problem in the original source code: The dimensions array needs to be the proper integer size for API calls, so you need to change this:
to this
Also, you may get a compiler warning on this conversion:
so I would change it to this instead: