How to grid data with coordinates to create a spatial plot using geoshow

8 ビュー (過去 30 日間)
Ronnie
Ronnie 2017 年 8 月 31 日
コメント済み: TAPAS 2018 年 6 月 12 日
I have 3 vectors: data, lat, lon which I am trying to plot spatially for the continental US. Is there a function where I can organize my lat and lon vectors in the appropriate gridded format which geoshow will plot properly while ensuring the data vector is organized in the same fashion so the data points remain with their respective coordinates?

採用された回答

Chad Greene
Chad Greene 2017 年 8 月 31 日
Is it possible that your data vectors are in fact regular, but simply not in gridded format? To check, try
scatterm(lat,lon,20,data)
If the datapoints are regularly spaced, you should be able to use my xyz2grid function like this:
[LON,LAT,DATA] = xyz2grid(lon,lat,data);
where lowercase are your data vectors and upper case are gridded. Then you can do
pcolorm(LAT,LON,DATA)
  13 件のコメント
Ronnie
Ronnie 2017 年 9 月 6 日
Update: I got it to work by trimming down the data even further (getting rid of NaN values) and then xyz2grid worked; and I am able to show the data using geoshow. Thank you so much for your help!
Chad Greene
Chad Greene 2017 年 9 月 7 日
Great, I'm glad you got it working!

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2017 年 8 月 31 日
編集済み: Chad Greene 2017 年 8 月 31 日
Let data be your nx3 array which has lon, lat and data in the first, second and column respectively.
% Get longitude and latitude vectors
x = unique(data(:,1)) ;
y = unique(data(:,2)) ;
% dimensions of the data
nx = length(x) ;
ny = length(y) ;
% Frame matrix of grid
D = reshape(data(:,3),[ny,nx]) ;
% flip matrix to adjust for plot
H = flipud(H) ;
% Transpose the matrix
H = H' ; % Check if is required
surf(x,y,H) ;
  16 件のコメント
Ronnie
Ronnie 2017 年 9 月 6 日
Thank you for the response! Much appreciation.
-Ronnie
TAPAS
TAPAS 2018 年 6 月 12 日
The code xyz2grid is not working it's showing mistake in line 31 in xyz read and line 72 in in xyz2grid

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by