How to plot a mashgrid within an ir-regular shape?
조회 수: 16 (최근 30일)
이전 댓글 표시
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).
채택된 답변
KSSV
2023년 5월 17일
편집: 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 ) ;
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) ;
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
추가 답변 (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!