How to interplote and meshgrid 2D scatter plot (bounded by an ir-regular surface)?

26 views (last 30 days)
Hi everyone,
I require interpolating a 2d scatter plot and then creating a mesh grid to find the average value within each grid cell along with the cell's central location.
Here is what i did so far:
Step 1: Plotting irregular surface
data=readmatrix('area.csv');
x=data(:,1);
y=data(:,2);
z=data(:,3);
plot(x, y, 'blue')
hold on
Step 2: Scatter plot
dat=readmatrix('combine.csv');
x1=dat(:,2);
y1=dat(:,3);
c1=dat(:,4);
plot(x1, y1, 'blue')
scatter(x1,y1,[],c1,'filled')
colorbar
colormap jet
hold off
To do ?
I require to plot these scatter pl;ot by interploation to get a higher resolution, like as below:
Additionally, I need to creat a mesh grid with teh bounded area and need to calcualte the depth value within each grid point along with the central location of grid.
Thank you!
(Data is attached).

Accepted Answer

Mathieu NOE
Mathieu NOE on 22 May 2023
hello
this should help you move forward
side by side the original plot and once resampled (grid data)
% Step 1: Plotting irregular surface
data=readmatrix('area.csv');
x=data(:,1);
y=data(:,2);
z=data(:,3);
plot(x, y, 'blue')
hold on
% Step 2: Scatter plot
dat=readmatrix('combine.csv');
x1=dat(:,2);
y1=dat(:,3);
c1=dat(:,4);
% plot(x1, y1, 'blue')
subplot(1,2,1),
scatter(x1,y1,[],c1,'filled')
title('original data')
colorbar
colormap jet
hold off
% create a mesh , and find points that are inside the border defined by x &
% y
N = 200;
[X,Y] = meshgrid(linspace(min(x),max(x),N),linspace(min(y),max(y),N));
in = inpolygon(X(:),Y(:),x,y);
xin = X(in);
yin = Y(in);
clear X Y
vq = griddata(x1,y1,c1,xin,yin);
subplot(1,2,2),
scatter(xin, yin, [], vq, 'filled')
title('resampled data')
colorbar
colormap jet
hold off

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!