# Meshgrid of Matlab to OpenCV

Hi,

translating this code from Matlab to C. Code of Matlab:

```
x = (-cols/2 : (cols/2 - 1))/(cols/2);
y = -(-rows/2 : (rows/2 - 1))/(rows/2);
[x,y] = meshgrid(x,y);
```

What I did in C/C++ is :

```
double x[cols],y[rows];
double X[cols][rows], Y[cols][rows];
double epsilon=0.0001;
for(int j=0;j<cols;j++){
for(int i=-(cols/2);i<=(cols/2)-1;i++){
x[j]= i/(cols/2);
}
}
for(int k=0;k<rows;k++){
for(int z=-(rows/2);z<=(rows/2)-1;z++){
y[k]= -z/(rows/2);
}
}
for(int i=0;i<cols;i++){
for(int z=0;z<rows;z++){
X[i][z]=x[i];
Y[i][z]=y[z];
}
}
```

Is it right?

Trying printing first elements of X (X[0][0],X[1][0]...) I have 0 ever. SO it s wrong. Someone know why? X[0][0] must be -1

You have posted quite a number of similar questions here - 20, more precisely. Instead of trying to use this forum as a means to find cheap labor for your project, why don't you simply learn C++?

And also use the search function of this Q&A forum, I have answered a similar question a while ago: http://answers.opencv.org/question/11788/is-there-a-meshgrid-function-in-opencv/