我正在优化一个模型,该模型需要一些天气数据,然后将云转换为多边形,以便进一步利用它们。
该代码正在运行,但它的速度很慢。通过运行分析器,我发现以下几行被调用106360430
了,处理时间大约为 50 秒。
有没有办法让这些线路更有效率?
function [oddNodes] = pointInPolygon (point,thePolygon)
% determine if a point is in the polygon (faster than matlab "inpolygon"command
polyPoints=size(thePolygon,1); % number of polygon points
oddNodes = false;
j=polyPoints;
x=point(1); y=point(2);
for i=1:polyPoints
if (thePolygon(i,2)<y && thePolygon(j,2)>=y || thePolygon(j,2)<y && thePolygon(i,2)>=y)
if (thePolygon(i,1)+(y-thePolygon(i,2))/(thePolygon(j,2)-thePolygon(i,2))*(thePolygon(j,1)-thePolygon(i,1))<x)
oddNodes=~oddNodes;
end
end
j=i;
end