Creating a Position Grid from Latitude and Longitude Points - matlab

I have two data sets: one of latitude and one of longitude. Both of these datum are 336x264 in size.
I would like to use MATLAB to turn this data into a grid of of position points.
So basically from this:
to this:
I don't want to reinvent the wheel here if there is a standardized method of going about this so I figured I should see if the community had any pre-existing resources for this sort of task!
Thank you and best,
Taylor

If you have the mapping toolbox, you can do this with the projfwd function:
% First, create the projection struct
mstr = defaultm('mercator'); %Or whatever projection you want to use
% Then, project your points
[x,y] = projfwd(mstr,lat,lon);

Related

Contour Plot of own coordinates with attached scalar

I have the following coordinate system of (x,y) and attached z value to each coordinate. I need to keep the coordinates the same without using some linear fit function to change it into a grid system of some sort. Is there a way i can create a contour of that data using that data only and not using griddata or something.
x=[0.2,0.2,0.05,1.1,0.8,0.9,1.8,1.9,2.05];
y=[0,1.1,2.1,0.1,1.1,2.2,0.15,1.1,2.05];
z=[0,1,0,0,2,1,0,1,0;];
plot(x,y, 'bo')
The reason is i have another model with 540 thousand coordinate points that is a weird shape and if i start using the other functions it loses its shape and goes rectangular.
One option you have is to use fitto create a fit surface of your data, and then directly plot it. This also has the advantage to give you extra parameters to control the interpolation between your points.
f=fit([x',y'],z','linearinterp')
plot(f,'Style','Contour')
Will create something like:
And
f=fit([x',y'],z','cubicinterp')
plot(f,'Style','Contour')
Will smooth the interpolation into:
Please look here for more information on fit and fit plotting options
https://www.mathworks.com/help/curvefit/fit.html#inputarg_fitType
https://www.mathworks.com/help/curvefit/plot.html

Using inpolyhedron Matlab

I am trying to use the function inpolyhedron shown here: https://www.mathworks.com/matlabcentral/fileexchange/37856-inpolyhedron-are-points-inside-a-triangulated-volume-
However, I am having trouble creating the polyhedron the way the function wants it defined (a structure with fields 'vertices' and 'faces'). The raw data I have is a matrix of points x y z that are inside the polyhedron. So far, I have been using boundary() and trisurf() to plot the polyhedron.
Dependant on what kind of polyhedron you want, you can use alphashape, delaunay triangulation or convhull. So for example:
shp=alphaShape(x,y,z);
h=plot(shp);
You can access faces and vertices then like:
h.Vertices
h.Faces
It works the same way for trisurf:
tri=delaunay(x,y,z)
t=trisurf(tri,x,y,z)
To see which information is stored, you can use get(t).
For faces and vertices it is the same thing as before:
t.Vertices
t.Faces

Convert image in polar to cartesian coordinates

I am trying to convert an image in polar to cartesian coordinates.
examples to convert image to polar coordinates do it explicitly - want a slick matrix method
I thought using the method used above would be a piece of cake but it really isn't!!
If anyone finds an error into my code please let me know!
phi=(0:.01:1)*2*pi;
r=0:.01:2;
psi=r<0.5;
psi_c=cos(phi).'*psi;
[P R z]=find(psi_c);
L=500;
X=R.*cos(P);
Y=R.*sin(P);
Xmin=min(X);Xmax=max(X);
Ymin=min(Y);Ymax=max(Y);
F=TriScatteredInterp(X,Y,z);
[Xi,Yi]=meshgrid(linspace(-Xmax,Xmax,L),linspace(-Ymax,Ymax,L));
Zi=F(Xi,Yi);
What I find very odd is the fact that when I change phi, it makes radical changes and not in the way I expect!
Cheers!
[X,Y] = pol2cart(THETA,RHO)
in case of conversion from polar grid to cartesian.
Likewise,
[X,Y] = pol2cart(THETA,RHO,Z)
to convert a cylindrical grid into the respective cartesian.
But I'm unsure those functions are what you need.

Finding weight of each grid in Matlab?

So I have two vectors*(x & y)* with x and y co-ordinate data points. I would like to put these points on grid kinda like a scatter plot and count the number of points within each grid like the weight of each grid using Matlab.
What would you guys suggest is the best way to do this? Any suggestion is appreciated
I assume you mean that you want to perform a 2D histogram of your x-y data.
You can use several tools from the file exchange:
http://www.mathworks.com/matlabcentral/fileexchange/9896-2d-histogram-calculation
http://www.mathworks.com/matlabcentral/fileexchange/1487
http://www.mathworks.com/matlabcentral/fileexchange/14205-2d-histogram

Matlab heatmap/topological map

I have 3 vectors of data: latitudes, longitudes, and elevations of specific locations. Each vector (lat, lon, elev) is a column vector with about 63 elements where element 1 of each represents a given location. What I want to do is create a topological map, or heatmap (whichever you want to call it) to map out these locations. I can plot them (like lon vs lat) no problem, but I'm not sure where to look to create a topological map. I've looked at using the surf function, but the elevations need to be a 2-D matrix for that and that would result in a lot of missing data that I just don't have.
Can someone give me some guidance here?
You can use TriScatteredInterp to interpolate your data onto a regular grid, which you then can use to plot the surface using surf, or a heatmap using contourf.
The example in the linked documentation of TriScatteredInterp will do exactly what you need, all you need to do is replace x, y, and z by your data and define the appropriate limits for meshgrid.