【matlab程序】连通区域内的数据提取方法以及实例应用

文摘   2024-05-09 16:54   德国  

先展示结果,图片比语言描述的清楚!

倒叙!


一、多联通区域内的数据全提取

二、提取多联通区域之间的数据

、提取单联通区域的数据


方法介绍:

inpolygon 位于多边形区域边缘内部或边缘上的点


in = inpolygon(xq,yq,xv,yv) 返回 in,以指明 xq 和 yq 所指定的查询点是在 xv 和 yv 定义的多边形区域的边缘内部还是在边缘上。


本文程序分享:

clear;clc;close all;% 构造数据% 定义 500 个随机点的 x 和 y 坐标。初始化随机数生成器以使 randn 的输出可重复。rng defaultxq = rand(1500,1)*10;yq = rand(1500,1)*10;zq = rand(1500,1)*10;% 数据网格化[x,y]=meshgrid(0:0.01:10,0:0.01:10);% 单点数据的网格化data = griddata(xq,yq,zq,x,y);% 颜色包cmap = colormore_6(500);
%% figureset(gcf,'Position',[50 50 850 850])contourf(x,y,data,100,'linestyle','none')axis equalcolormap(cmap)export_fig(gcf,'数据情况一.jpg')%% 多边形区域L = linspace(0,2*pi,50);xv = cos(L)'+5;yv = sin(L)'+5;% figureset(gcf,'Position',[50 50 850 850])contourf(x,y,data,100,'linestyle','none')axis equalcolormap(cmap)%hold onplot(xv,yv,'LineWidth',2,'Color','r') % polygonexport_fig(gcf,'多边形区域线条一.jpg')%% 提取多边形区域内的数据[in,on] = inpolygon(x,y,xv,yv);data_in = data.*in;data_in(data_in==0)=nan;figureset(gcf,'Position',[50 50 850 850])contourf(x,y,data_in,100,'linestyle','none')axis equalcolormap(cmap)%hold onplot(xv,yv,'LineWidth',2,'Color','r') % polygonexport_fig(gcf,'多边形区域一.jpg')




data_in = data.*(1-in);data_in(data_in==0)=nan;figureset(gcf,'Position',[50 50 850 850])contourf(x,y,data_in,100,'linestyle','none')axis equalcolormap(cmap)%hold onplot(xv,yv,'LineWidth',2,'Color','r') % polygonexport_fig(gcf,'多边形区域一1.jpg')

clear;clc;close all;% 构造数据% 定义 500 个随机点的 x 和 y 坐标。初始化随机数生成器以使 randn 的输出可重复。rng defaultxq = rand(1500,1)*10;yq = rand(1500,1)*10;zq = rand(1500,1)*10;% 数据网格化[x,y]=meshgrid(0:0.01:10,0:0.01:10);% 单点数据的网格化data = griddata(xq,yq,zq,x,y);% 颜色包cmap = colormore_10(500);
%% figureset(gcf,'Position',[50 50 850 850])contourf(x,y,data,100,'linestyle','none')axis equalcolormap(cmap)export_fig(gcf,'数据情况一.jpg')%% 多边形区域L = linspace(0,2*pi,50);xv = 3*cos(L)'+5;yv = 3*sin(L)'+5;xv1 = cos(L)'+5;yv1 = sin(L)'+5;
% figureset(gcf,'Position',[50 50 850 850])contourf(x,y,data,100,'linestyle','none')axis equalcolormap(cmap)%hold onplot(xv,yv,'LineWidth',2,'Color','r') % polygonplot(xv1,yv1,'LineWidth',2,'Color','b') % polygonexport_fig(gcf,'多边形区域线条2.jpg')%% 提取双连通多边形区域内的数据%定义一个带有方孔的方形区域。按逆时针方向指定外循环的顶点,% 并按顺时针方向指定内循环的顶点。使用 NaN 隔开外循环和内循环的坐标。
xv_new = cat(1,xv,nan,flip(xv1));yv_new = cat(1,yv,nan,flip(yv1));

[in,on] = inpolygon(x,y,xv_new,yv_new);data_in = data.*in;data_in(data_in==0)=nan;figureset(gcf,'Position',[50 50 850 850])contourf(x,y,data_in,100,'linestyle','none')axis equalcolormap(cmap)%hold onplot(xv,yv,'LineWidth',2,'Color','r') % polygonplot(xv1,yv1,'LineWidth',2,'Color','b') % polygonexport_fig(gcf,'多边形区域2.jpg')

data_in = data.*in;data_in1 = data.*(1-in);data_in1(data_in1==0)=nan;
figureset(gcf,'Position',[50 50 850 850])% contourf(x,y,data_in,100,'linestyle','none')hold oncontourf(x,y,data_in1,100,'linestyle','none')axis equalcolormap(cmap)%hold onplot(xv,yv,'LineWidth',2,'Color','r') % polygonplot(xv1,yv1,'LineWidth',2,'Color','b') % polygonexport_fig(gcf,'多边形区域3.jpg')



【matlab程序】连通区域内的数据提取方法以及实例应用


海洋与大气科学
海洋与大气科学数据分析,数据可视化分享,可教学。
 最新文章