Effacer les filtres
Effacer les filtres

How do I find values at geographic coordinates in a matrix?

3 vues (au cours des 30 derniers jours)
Pema
Pema le 30 Jan 2014
Commenté : Amit le 30 Jan 2014
How can I find the values of the matrix R , which geographic coordinates are specified by x and y matrices, at the geographic coordinates specified by Ax and Ay vectors? Exactly matching coordinates of Ax,Ay does not exist in x,y so I guess there is a need to include some interpolation.
Help is much appreciated!
Example:
R = magic(5);
x = [1:5;1:5;1:5;1:5;1:5];
y = x';
Ax = [1,2,3,4,5];
Ay = [3,4,3,4,3];
% for illustration
% I want to find the values of R where the line crosses
hold on
contourf(x,y,R)
plot(Ax,Ay)
hold off
  1 commentaire
Amit
Amit le 30 Jan 2014
A little more description please. like what is R

Connectez-vous pour commenter.

Réponse acceptée

Amit
Amit le 30 Jan 2014
I think interpolation will be the route.
You can use interp2. For the example here,
R_int = interp2(X,Y,R,Ax,Ay);
  4 commentaires
Pema
Pema le 30 Jan 2014
It turns out, x and y needs to be monotonic for 'interp2', which they are not in my field data. 'griddata' function did the trick.
Amit
Amit le 30 Jan 2014
Good. If it works for you, then you should accept the answer!

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 30 Jan 2014
Yes, you would need to do some sort of interpolation.
You have the difficulty that interpolations that depend upon distance from existing elements are not going to work properly for geographic coordinates because of projection issues. The worst location would, I think, be at the centroid of the surrounding coordinates. If your grid is finely enough grained then you might be willing to overlook that. If you do need to take it into account, you would need to project the geographic coordinates onto a flat map before doing the interpolation (using TriScatteredInterp or GriddedInterpolant). That projection is going to lead to trouble by itself near the boundaries of the projection (e.g., the poles).
  1 commentaire
Pema
Pema le 30 Jan 2014
Thanks! I think I was a bit confusing using the term 'geographic' though, my data does not need to be projected on a sphere. It's in plain 2d already.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Geographic Plots dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by