Reshape or convert vectors to use it with pcolor
14 次查看(过去 30 天)
显示 更早的评论
Hi,
I'm using a model which gives the data as vectors:
whos -file ~/data.mat
Name Size Bytes Class Attributes
lat 21242x1 169936 double
lon 21242x1 169936 double
sss 21242x1 169936 double
In order to generate a plot I've been using scatter function as:
scatter(lon,lat,[],sss)
It's possible to convert the data in some way to use pcolor or contourf? I'm interested on gradients and for this both pcolor and contour are better. I've tried with reshape but the result is not optimal since connects points in the wrong way. I've also tried to generate a grid, and fill this out with the data from the original grid but this is also not optimal since the original grid is not structured.
Does anyone has any suggestions?
Best,
Edit: Improve the reason for asking.
3 个评论
回答(1 个)
Robert Daly
2023-8-11
pcolor or contourf need gridded data to plot.
What do you mean when you say "filling a gid is not optimal since the original grid is not structured".
Are you trying to acheive a plot with triangular tesselation? I am not sure if there is a function that does that.
My suggestion would be just to create a fine rectangular grid and interpolate your data onto it using scatteredInterpolant.
load("data.mat")
[X,Y] = meshgrid(linspace(min(lon),max(lon),500),linspace(min(lat),max(lat),500));% make 500x500 grid
f = scatteredInterpolant(lon,lat,sss); % set up the interpolater with your data
SSS = f(X,Y); % Do the interpolation onto the grid set up above
perimeter = boundary(lon,lat,1); % find the outer boundary of the data
in = inpolygon(X,Y,lon(perimeter),lat(perimeter)); % find the data inside the boundary
SSS(~in) = nan; % make everythign outside the boundary "nothing"
figure
pcolor(X,Y,SSS)
shading flat
1 个评论
Robert Daly
2023-8-11
Does anyone have a good strategy for eliminating the "holes" inside the shape. I am guessing this is some sort of lake and the holes are islands. Can we use something like boundary again?
My goto would be to add some points to the end of the lat and lon vectors that represent the inside of the islands and then add the same number of nan values to the 'sss' vector.
Possibly you could create points using 'ginput' and a scatter plot of your lat & lon vectors.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!