Interpolate scattered latitude and longitude (climate) data and plot
Show older comments
Hello everyone,
I have a table with 3 columns: latitude, longitude, and climate information. I want to plot these points on my map and have a color bar.
I want to interpolate them to achieve a zoning map.
I have a figure of the country as you can see below:

Using this code:
borders('Iran Islamic Republic of') % borders is a 3rd party function from matlab file exchange by Chad A. Greene
grid on
ax.GridLineStyle = '-';
% Modify the X and Y ticks positions
xticks(44:.5:65);
yticks(25:.5:40);
xlabel('Longitude')
ylabel('Latitude')
xtickangle(90)
set(gca,'FontSize',5)
set(hTitle,'FontSize',16)
xlabel('Longitude','FontSize',10,'FontWeight','bold','Color','r')
ylabel('Latitude','FontSize',10,'FontWeight','bold','Color','r')
I was tried to plot the value of latitude and longitude on a map using this code:
hold on
geoshow(SPI_for_certain_date.lat, SPI_for_certain_date.lon, SPI_for_certain_date.SPI_1month, 'displaytype', 'texturemap');
colorbar('vert','FontSize',12);
But it does not work and shows me this warning:
Warning: Error creating or updating Surface
Error in value of property ZData
Array is wrong shape or size
Warning: Error creating or updating Surface
Error in value of property ZData
Array is wrong shape or size
And so here my figure after that:

Now I don't know what should I do. The color bar understands the range of my data accurately but unfortunately data not plotted on my map. To check if everything is okay I plot just latitude and longitude on my map (without corresponding rainfall data) using pcolor and it works and points presented on a map.
Actually I want to do something like this code that I found it from Google (Internet):
% some sample data, located in europe
data = [randi([-10 30],10,1) randi([30 50],10,1) rand(10,1)];
lat = data(:,1);
lon = data(:,2);
temp = data(:,3); % : not ;
lon0 = min(lon) ; lon1 = max(lon) ;
lat0 = min(lat) ; lat1 = max(lat) ;
N = 100 ;
x = linspace(lon0,lon1,N) ;
y = linspace(lat0,lat1,N) ; % lat0, not lon1
[X,Y] = meshgrid(x,y) ;
F = scatteredInterpolant(lon,lat,temp) ;
Z = F(X,Y) ;
worldmap('World')
load coastlines
plotm(coastlat,coastlon)
geoshow(X,Y,Z,'DisplayType', 'texturemap') % options give it a nice colormap for temperature - but you might want to change them to something more of your taste
Here is world map I want to plot my file that I attahced on my map that I mentiond above.
As the original file (latitude longitude and values) is very large for attaching here, I cut part of it and so I attache an example file with a small size here.
Thank you so much in advance
UPDATE
I want something like this map.

1 Comment
darova
on 8 Feb 2020
I tried using griddata
The result:

Accepted Answer
More Answers (0)
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



