Reshape or convert vectors to use it with pcolor

11 views (last 30 days)
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.

Answers (1)

Robert Daly
Robert Daly on 11 Aug 2023
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 Comment
Robert Daly
Robert Daly on 11 Aug 2023
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.

Sign in to comment.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!