![](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)?
28 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Mathieu NOE
2023-5-22
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!