How to plot global temperatures interpolated on world map from a mat file

37 views (last 30 days)
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
  2 Comments
Name Tag
Name Tag on 3 Jul 2019
I attached the .mat file below. First row cells are lon; first column is lat - in decimal degrees. The rest are temperatures. I want to generate on a world map the temps interpolated. I would prefer to generate directly in Matlab, if possible, but also looking for straighforward simplicity - as much as possible - in code and steps. Thanks for the help.

Sign in to comment.

Answers (1)

KSSV
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
Name Tag
Name Tag on 8 Jul 2019
Edited: Name Tag on 8 Jul 2019
I needed to edit the code to get the plot: here's the plot and the revised code underneath. I don't understand why it only works when lat and lon are flipped (see ?s), but not when both are flipped back as normal. I've seen others ask about the same problem of incomplete plots generated when the obivious inputs are made, and they don't get responses. Any ideas?
incT2.jpg
load('T_file.mat');
T_file = double(T_file) ;
A=T_file;
lat=A(:,2); %? my lon
lon=A(:,1); %? my lat
z=A(:,3);
lon0 =(-90) ; lon1 = (90) ; % lat limits ?
lat0 = (0) ; lat1 = (360) ; % lon limits ?
N = 100 ;
x = linspace(lon0,lon1,N) ;
y = linspace(lat0,lat1,N) ; %not lon1
[X,Y] = meshgrid(x,y) ;
F=scatteredInterpolant(lon,lat,z) ;
Z = F(X,Y) ;
worldmap('world') % initializes map
c = load('coast.mat'); % loads coastlines
plotm(c.lat,c.long) % plots coastlines
geoshow(X,Y,Z,'DisplayType', 'surface');

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!