How to plot a mashgrid within an ir-regular shape?

Hi everyone,
I am looking to plot a meshgrid figure with an irregualr shape and then need to need the grids within a bounded regions along with the central location of each grid point.
Here is what i did so far:
% Step 1: Create a rectangualr meshgrid considering the region of
% ir-regualr bounded area
clear all
clc
x=72.68:0.005:72.97;
y=34:0.005:34.7;
n = length(x ) ;
m = length(y ) ;
[X,Y] = meshgrid(x,y ) ;
plot(X,Y,'r',X',Y','r ')
%Result is as below
Step 2: Plot dimensions of the bounded area over the meshgrid map
clear all
clc
x=72.68:0.005:72.97;
y=34:0.005:34.7;
n = length(x ) ;
m = length(y ) ;
[X,Y] = meshgrid(x,y ) ;
plot(X,Y,'r',X',Y','r ')
hold on
data=readmatrix('dam_area.csv');
x1=data(:,1);
y1=data(:,2);
z1=data(:,3)*0;
plot(x1, y1, 'blue')
%Result as below
What I need at the first stage?
I want to delete all the grid outside the bounded area and only keep the griids inside the bounded area.
expected results as below (@KSSV help in plotting this, but not very sure about the approach)
What else I need?
I require to know the central value (lat, long values, assume z here zero) of each grid (with the bounded area) so i can use thouse central values to plot other parameteres with the same grids.
Thank you!
(Data is attached).

2 件のコメント

KSSV
KSSV 2023 年 5 月 17 日
Share your csv file.....
Andi
Andi 2023 年 5 月 17 日
@KSSV Apology, I have already uploaded the csv file.

サインインしてコメントする。

 採用された回答

KSSV
KSSV 2023 年 5 月 17 日
編集済み: KSSV 2023 年 5 月 17 日

0 投票

clc; clear ;
x=72.68:0.005:72.97;
y=34:0.005:34.7;
n = length(x ) ;
m = length(y ) ;
[X,Y] = meshgrid(x,y ) ;
data=readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1385964/area.csv/area.csv');
x=data(:,1);
y=data(:,2);
z=data(:,3);
F = scatteredInterpolant(x,y,z) ;
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Z = F(X,Y) ;
%x = axil_long ; y = axil_lat ; z = time_axil(:,1) ;
[in,on] = inpolygon(X,Y,x,y) ;
idx = in|on ;
X(~idx) = NaN ;
Y(~idx) = NaN ;
Z(~idx) = NaN ;
figure
h = pcolor(X,Y,Z) ;
h.EdgeColor = 'none';
figure
plot(X,Y,'r',X',Y','r ')
xlabel('Longitude (E{\circ})')
ylabel('Latitude (N{\circ})')
axis([72.68 72.97 34 34.7])

8 件のコメント

Andi
Andi 2023 年 5 月 17 日
編集済み: Andi 2023 年 5 月 17 日
@KSSV Thanks this works well, can I get the central location of each grid point of the mesh grid, so I can place other parameters within each grid?
My major task is to find the central points (lat, long) of each grid with the bounded area and then fill each grid cell with other parameters one by one.
KSSV
KSSV 2023 年 5 月 17 日
% Central location
xc = x(1)-0.0025:0.005:x(end)-0.0025;
yc = y(1)-0.0025:0.005:y(end)-0.0025;
[Xc,Yc] = meshgrid(xc,yc) ;
Andi
Andi 2023 年 5 月 17 日
編集済み: Andi 2023 年 5 月 17 日
@KSSV Thanks for help! I think it still only give one point whereas i am looking for centeral point of all the grids within the bounded region.
KSSV
KSSV 2023 年 5 月 17 日
Use Xc, Yc as you have used X, Y. Xc, Yc are central points.
Andi
Andi 2023 年 5 月 17 日
@KSSV Thanks, but I think my objective is a bit different. Let me try to explain it a bit clearer.
x=72.68:0.005:72.97;
y=34:0.005:34.7;
Above x, and y are the grid points over the whole area.
data=readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1385964/area.csv/area.csv');
x1=data(:,1);
y1=data(:,2);
z1=data(:,3)*0; % assume z=0 here
x1, y1 are marked as the boundary of the enclosed area over the x, y grid. Next, I want to find the grids lying with the x1, y1 area and their central values, so I can use that central values to plot other parameters with each grid point.
I am trying to get through what you explained to me, but still not very clear to me.
May you assist me here? Thank you!
KSSV
KSSV 2023 年 5 月 17 日
clc; clear ;
x=72.68:0.005:72.97;
y=34:0.005:34.7;
n = length(x ) ;
m = length(y ) ;
[X,Y] = meshgrid(x,y ) ;
% Central location
xc = x(1)-0.0025:0.005:x(end)-0.0025;
yc = y(1)-0.0025:0.005:y(end)-0.0025;
[Xc,Yc] = meshgrid(xc,yc) ;
data=readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1385964/area.csv/area.csv');
x=data(:,1);
y=data(:,2);
z=data(:,3);
F = scatteredInterpolant(x,y,z) ;
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Z = F(X,Y) ;
%x = axil_long ; y = axil_lat ; z = time_axil(:,1) ;
[in,on] = inpolygon(X,Y,x,y) ;
idx = in|on ;
X(~idx) = NaN ;
Y(~idx) = NaN ;
Z(~idx) = NaN ;
[in,on] = inpolygon(Xc,Yc,x,y) ;
idx = in|on ;
Xc(~idx) = NaN ;
Yc(~idx) = NaN ;
figure
hold on
plot(X,Y,'r',X',Y','r ')
plot(Xc,Yc,'.b')
xlabel('Longitude (E{\circ})')
ylabel('Latitude (N{\circ})')
axis([72.68 72.97 34 34.7])
Andi
Andi 2023 年 5 月 17 日
@KSSV Thanks for the updated results, I am trying to test it on the actual data set. Meanwhile, I also updated my primary question for clarity.
Andi
Andi 2023 年 5 月 18 日
@KSSV I attempt to fix the probelm with the gridding approch but it did not work well, so i move to another approch.
Step 1: Plooting the boundary of ir-regular shape
data=readmatrix('dam_area.csv');
x=data(:,1);
y=data(:,2);
z=data(:,3);
plot(x, y, 'blue')
hold on
Step 2: Plotting the z-parameteres as a color color within the bounded area
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
What I required:
  1. Interpolate all the scatter points and make a surface plot (figure attached below).
  2. The mesh grid is this bounded area and gets the central point of each mesh grid along with the average value of the z-parameter.
Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

製品

タグ

質問済み:

2023 年 5 月 17 日

コメント済み:

2023 年 5 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by