MATLAB: Check if Lat, Lon coordinate fall inside a polyshape Polygon

inpolygonisinteriorMapping ToolboxMATLABpolyinpolyshape

I am attempting to create a for loop that goes through a workbook and plot a polygon for each spreadsheet in the workbook. Each polygon has a limit value. My goal is to create another plot with only points that have a value less than the polygon limit and also that fall inside that same polygon. That process is done for each polygon in each spreadsheet.
The issue I am having is when I check if the point is within the polygon, the logical return is zero for every point inside the polygons. I am certain that's not true. The polygons are made of Lat and lon coordinates and so are the points.I tried using "isinterior" and 'inpolygon" I get the same results. I would like to know what am I missing. I could not anything helpful on the forums to help me get over this hump.
This is the part of the code that checks for that:
for i = 1 : nSheet %nSheet is the number of sheet. Which defines number of polygons
Polyin = polyshape(boundlon{i}(:,1),boundlat{i}(:,1));
for j = 1:size(Pfd_value,1) %Pfd_value is a 356X1 double
%TFin = inpolygon(Pfd_lon(j),Pfd_lat(j),finalplot.Longitude,finalplot.Latitude);
TFin = isinterior(Polyin,Pfd_lon(j),Pfd_lat(j));
if Pfd_value(j) <= Limit_range(i) && TFin == 1 %Limit_range is the constantlimit for each polygon
colormap(hsv(size(Pfd_value,1)));
geoscatter(Pfd_lat(j),Pfd_lon(j),[],Pfd_value(j),'o','filled');
end
end
end

Best Answer

I think your inputs to inpolygon need to be the points. Try using the inputs to polyshape. inpolygon can test a vector of query points. Here's a sample (untested).
TFin = inpolygon(Pfd_lon,Pfd_lat,boundlon{i}(:,1),boundlat{i}(:,1));