![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1390734/image.png)
How to interplote and meshgrid 2D scatter plot (bounded by an ir-regular surface)?
13 views (last 30 days)
Show older comments
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1387284/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1387289/image.png)
To do ?
I require to plot these scatter pl;ot by interploation to get a higher resolution, like as below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1387294/image.png)
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).
0 Comments
Accepted Answer
Mathieu NOE
on 22 May 2023
hello
this should help you move forward
side by side the original plot and once resampled (grid data)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1390734/image.png)
% 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
0 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!