How to grid data with coordinates to create a spatial plot using geoshow
이전 댓글 표시
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?
채택된 답변
추가 답변 (1개)
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 Abolafia-Rosenzweig
2017년 8월 31일
In this solution, using the unique function to create latitude and longitude vectors will erase any duplicates of latitude and then any duplicates of longitude. It is okay to have multiple latitude readings, as long as they are paired with different respective longitude readings. I do not want to erase data points from the vectors. Both vecotrs (lat and lon) have already been updated to ensure that there are no duplicate coordinates.
I am seeking for a way to transform vectors in matrices which can be read by the function geoshow.
KSSV
2017년 8월 31일
The above code works..if your data is a structured grid and in (x,y,z) format......if it is unstructured grid, you need to follow the below:
x0 = min(lon) ; x1 = max(lon) ; nx = 100 ;
y0 = min(lat) ; y1 = max(lat) ; ny = 100 ;
x = linspace(x0,x1,nx) ;
y = linspace(y0,y1,ny) ;
[X,Y] = meshgrid(x,y) ;
Z = griddata(lon,lat,data,X,Y)
surf(X,Y,Z)
Ronnie
2017년 8월 31일
Ronnie
2017년 8월 31일
KSSV
2017년 8월 31일
Attach your data...it shall work...
Ronnie Abolafia-Rosenzweig
2017년 9월 1일
I appreciate your help. I will send the data tomorrow once I am back at the computer!
Ronnie
2017년 9월 1일
KSSV
2017년 9월 2일
Week end...I will get back to you on Monday ..:)
Ronnie Abolafia-Rosenzweig
2017년 9월 2일
Enjoy the weekend, I will not have access to my computer until Monday as well. :)
KSSV
2017년 9월 4일
Where is .mat file?
Ronnie Abolafia-Rosenzweig
2017년 9월 4일
The site will not allow me to send any files greater than 5 MB, which the lat and data files are. The LON.mat file was bellow the size limit and is attached. Can you please send me an email at ronnie.aggie2016@gmail.com and I will respond with the .mat files. I apologize for the inconvenience
KSSV
2017년 9월 5일
You may attach the file in your google drive and past the link here......
Ronnie Abolafia-Rosenzweig
2017년 9월 5일
편집: KSSV
2017년 9월 6일
It should allow you full access. Thank you
KSSV
2017년 9월 6일
This works....
lon = load('LON.mat') ;
lon = lon.lon ;
lat = load('LAT.mat') ;
lat = lat.lat ;
data = load('DATA.mat') ;
data = data.data ;
%%remove -9999
data(lon==-9999) = [] ;
lon(lon==-9999) = [] ;
lat(lat==-9999) = [] ;
scatter(lon,lat,data,data)
Ronnie
2017년 9월 6일
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
카테고리
도움말 센터 및 File Exchange에서 Lengths and Angles에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!