Reshape or convert vectors to use it with pcolor

14 Ansichten (letzte 30 Tage)
user20912
user20912 am 7 Aug. 2023
Kommentiert: Robert Daly am 11 Aug. 2023
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 Kommentare
user20912
user20912 am 7 Aug. 2023
This is an example of the data.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Robert Daly
Robert Daly am 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 Kommentar
Robert Daly
Robert Daly am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by