Home Matlab mesh step
Reply: 0

Matlab mesh step

user2697 Published in August 15, 2018, 8:58 am

I'm developing a tool in Matlab where I use meshgrid

    x= -a:a/101:a;
    y= -a:a/101:a;
[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 ideal_computations and 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?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.259651 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO