필터 지우기
필터 지우기

Reshape or convert vectors to use it with pcolor

조회 수: 17 (최근 30일)
user20912
user20912 2023년 8월 7일
댓글: Robert Daly 2023년 8월 11일
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
user20912
user20912 2023년 8월 7일
This is an example of the data.
Cris LaPierre
Cris LaPierre 2023년 8월 7일
load data.mat
scatter(lon,lat,[],sss)

댓글을 달려면 로그인하십시오.

답변 (1개)

Robert Daly
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
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 CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by