Plot bilinear interpolated gridded data spatially on a map - matlab

I am using the following code to plot gridded data on a map over a region but I would like to know how to plot the interpolated data so that I get continuous data plotted over the region and the data does not look gridded. 'lat' and 'lon' are vectors (1x21 and 1x33) containing the latitude and longitude coordinates respectively.
ax = worldmap(latlim, lonlim);
S = shaperead('landareas','UseGeoCoords',true);
surfacem(lat, lon, ans');
geoshow([S.Lat], [S.Lon],'Color','black');
I am seeing a lot of documentation on using interp2 but I am not getting mine to work even when I try to create a meshgrid using lat and lon (cannot attach the data). I do the following with interp2:
LON,LAT] = meshgrid(unique(lon),unique(lat));
interp2(lon, lat, testdata', LON, LAT);
That gives me a result but I then want to plot it over a region without it looking gridded. testdata is a 33x21 matrix. Any ideas? I have seen some examples here on interpolation but I am not sure how to apply it conveniently with the data I have. I am surprised that there is not more information on this or why I am just sucking at finding the answer!
Thanks,

Related

matlab 4D interpolation plot

Here is a sample dataset.
x = linspace(10,20,50);
y = linspace(10,20,50);
z = cos(linspace(0,2*pi,50));
time = linspace(1,60,50);
sci_temp = randi(100,50,1);
x,y,z is position, and sci_temp is temperature data.
I wonder how to draw trajectory over xyz position with sci_temp data.
I try interpolate data, so I get 2D interpolate time vs z with sci_temp plot.
S = TriScatteredInterp(time',z',sci_temp);
[t_mesh z_mesh] = meshgrid(time,z);
tz_mesh = S(t_mesh, z_mesh);
pcolor(t_mesh,z_mesh,tz_mesh)
What I want to get is a 2D (time vs sci_temp) section map on a xyz 3D plot. Like this image.
how to show trajectory over sci_temp in 3D plot?
Is there anyone can help me?
Thanks
First, you are doing your interpolation slightly wrong, you don't want to interpolate over the mesh created by
meshgrid(time,z);
Because it will duplicate values. You want to interpolate over the mesh created by
meshgrid(time,linspace(min(z),max(z),50));
Once you get the interpolated values like:
You can plot them in 3D space with the surface function, you just need to make sure to give x and y coordinates appropriately
surface(repmat(x,50,1),repmat(y,50,1),zmesh,tzmesh)
You can even have more complex paths, for example, same data but y=z
Edit: Also I forgot to mention, I'd suggest you to use scatteredInterpolant instead of TriScatteredInterp. It gives you more control over the interpolation

In MATLAB, how can I combine 2 different `histc` results into one, and produce a 3D plot?

In one histc, I have latitude data. In another histc, I have longitude data. I have plotted the bar graphs of these 2 separately. Now, I want to combine them and produce a 3D graph where the x-axis is latitude, y-axis is longitude, and z-axis is the frequency with which each latitude-longitude pair occurs.
The problem is that, while plotting the graphs for latitudes and longitudes separately, I calculated their respective frequencies by taking their individual histcs separately. However, when I want to make it a 3D plot, I can't seem to find a way to take the histc of the latitude-longitude pairs.
EDIT: I am adding my code for plotting the bar graphs here upon being asked by one commenter to do so, though I don't see how that would help. The bar graph for latitude is: bar(unique(M), histc(M,unique(M))) and that for longitude is bar(unique(N), histc(N,unique(N))). And the M and N are nx1 matrices. (Actually, they are 2 columns of a much larger matrix. But for simplicity in comprehension, I have avoided writing complex formulae here.)
EDIT: I reckon what I am looking for might be solved by surface plot, surf. But I am not sure. If it is, then the issue I am facing, speaking in terms of surf, can be stated as an issue in defining the Z parameter.
latitudes=180*(rand(1,10000)-0.5);
longitudes=360*(rand(1,10000)-0.5);
d=[latitudes;longitudes];
minVal_Lat=-90;
maxVal_Lat=90;
minVal_Long=-180;
maxVal_Long=180;
delta=10;
axisLat=minVal_Lat:delta:maxVal_Lat;
axisLong=minVal_Long:delta:maxVal_Long;
nPDF_Lat=length(axisLat);
nPDF_Long=length(axisLong);
PDF=zeros(nPDF_Lat,nPDF_Long);
temp=0;
count_i=1;
count_j=1;
for i=axisLat;
lowlimit_x=i-delta/2;
upperlimit_x =i+delta/2;
for j=axisLong;
lowlimit_y=j-delta/2;
upperlimit_y =j+delta/2;
temp=0;
for k=1:length(d(1,:));
if lowlimit_x<=d(1,k) & d(1,k)<upperlimit_x
if lowlimit_y<=d(2,k) & d(2,k)<upperlimit_y
temp=temp+1;
else
end
else
end
end
PDF(count_i,count_j)=temp;
count_j=count_j+1;
end
count_i=count_i+1;
count_j=1;
end
normFactor=sum(sum(PDF));
PDF=(1/normFactor)*PDF;
randVar_Lat=minVal_Lat:delta:maxVal_Lat;
randVar_Long=minVal_Long:delta:maxVal_Long;
surf(randVar_Lat,randVar_Long,PDF')
If you want get a 2D probability density function with surf plot, these codes will be worked.

Plot lat and lon grid on a world map using Matlab

Can anyone help me how to plot latitude and longitude on a world map using matlab. I have the mapping toolbox and have been trying to use the function geoshow, however I canĀ“t get it right. I plot the world map using plot_google_map:
plot(lon,lat,'.k','MarkerSize',6)
hold on
plot_google_map('maptype','roadmap')
This is the figure I get:
However I am not able to get the latitude and longitude grid on this picture.
I'm not sure is this going to help, but try reversing the order of your plot statements - its possibly that the map plot may be overwriting all the data of the lon and lat data.
Alternatively, if the function allows for it, plot the map as the back layer.

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.

time series plot on google earth using matlab

I have three sets of data:
time
longitude
latitude
I would like to plot this on google earth using google earth toolbox for matlab, what i need is when i move the time slider a line should be drawn on google earth.
I tried this
x = [longitude, latitude];
y = time;
kmlStr = ge_plot(x,y);
But an error occured.
On the other hand ge_gplot does not make sense for this.
Is there a way i can do this timeseries plot using google earth toolbox?
Create two vectors: one for x (longitude), one for y (latitude). ge_plot(x,y) will draw a line connecting each pair of (x,y) points in these vectors.
If you want to draw the line as a slider advances, then you need to make use of a callback function. In this function, do ge_plot(x(1:ind), y(1:ind) ) where ind is determined by the "time" value of the slider.