I'm developing a tool in Matlab where I use
[X,Y] = meshgrid(x,y);
to define the points where a field
E is computed. Therefore I have
E(X,Y) and in this way I would have that for a specific point in the mesh, it's associate a value for the field. I have a function that compute E in all the points
E = compute_field(X,Y)
Then I do some operation to this field (sums and multiplications) inside another function which give me two results representing all the possible errors in the two directions.
[ERR_H,ERR_V] = ideal_computations(E,X,Y)
So far there are no problems.
In the next step of my tool I decide to impose the two points x,y to extract the value of this field in order to have
E(x,y) scalar and not matrix like before
e = compute_field(x,y)
and I do exactly the same sums and multiplications that I did before.
[ERR_H,ERR_V] = real_computations(e,x,y)
For now the two functions
real_computations are exactly the same.
Then I check where
E(x,y) is inside
E(X,Y) computing the minimum value between the two and extract the coordinates and the problem is here.
[x1_est,x2_est] = compute_error(err_h,err_v,X,Y,ERR_H,ERR_V)
row = (size(ERR_H,1)+1)/2;
col = (size(ERR_V,2)+1)/2;
[~,m] = min(abs(ERR_H(row,:)-err_h));
[~,n] = min(abs(ERR_V(:,col)-err_v));
x1_est = X(n,m);
x2_est = Y(n,m);
Probably the couple
(X,Y) doesn't have the step to match perfectly
(x,y) and I get this
This probably happens when I compute the minimum and the result is not exactly zero, therefore there is this kind of mismatch.
For example I put the points
(0.0651,0.0651). This function go check the position of that point, or the one that is close to
0.0651. Looking at the matrices, I see that the closest value is
0.065076334365630, which is not exactly
0.0651. To get min=0 I should have inside the matrices the value 0.0651 and in that case I will have the two points overlapped.
I don't want to increase the step because maybe could even work with this field but maybe not with another one, plus I will have a very large matrices that will need to much effort to be computed.
How can I solve this problem? Is there any other ways to do the same not using meshgrid but something that always works?