How to plot global temperatures interpolated on world map from a mat file
Show older comments
Hello, I'm still working on this. I removed my previous data file. I am uploading a new mat file with the three columns I figured out how to extract, since I tried to make a shp file. I found the code given to another question about plotting scattered interpolated data, but when I apply it on my file (I just loaded the T-file.mat I'm attaching here) I get the error:
Index in position 2 exceeds array bounds (must not exceed 1).
Error in Tmap3 (line 3)
lon=A(:,2);
Here is the code I tried to use on my mat file data, but what I really want to do is ineterpolate the temperature data on a world map. I made two shape files and Matlab is only reading the shp file with lat and lon, not the one that includes the data. Please Help!
A=load('T_file.mat');
lat=A(:,1);
lon=A(:,2);
z=A(:,3);
lon0 = 0 ; lon1 = 360 ;
lat0 = -90 ; lat1 = 90 ;
N = 100 ;
x = linspace(lon0,lon1,N) ;
y = linspace(lon1,lat1,N) ;
[X,Y] = meshgrid(x,y) ;
F = scatteredInterpolant(lon,lat,z) ;
Z = F(X,Y) ;
worldmap('world') % initializes map
contourm(X,Y,Z) % plots contours
c = load('coast.mat'); % loads coastlines
plotm(c.lat,c.long) % plots coastlines
Answers (1)
KSSV
on 8 Jul 2019
A=load('T_file.mat');
T_file = double(T_file) ;
lon=A(:,1);
lat=A(:,2);
z=A(:,3);
lon0 = min(lon) ; lon1 = max(lon) ;
lat0 = min(lat) ; lat1 = max(lat) ;
N = 1000 ;
x = linspace(lon0,lon1,N) ;
y = linspace(lon1,lat1,N) ;
[X,Y] = meshgrid(x,y) ;
F = scatteredInterpolant(lon,lat,z) ;
Z = F(X,Y) ;
worldmap('world') % initializes map
contourm(X,Y,Z) % plots contours
c = load('coast.mat'); % loads coastlines
plotm(c.lat,c.long) % plots coastlines
1 Comment
Categories
Find more on Create Plots on Maps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!