MATLAB: Points inside multiple polygon for contour

contourcontourtableinpolygonMATLABmultiple polygons

I made the following contourplot.
Then, I plot discretized points over this plot.
I wanted to find the (x,y) coordinates of the discretized points within the region between the boundaries 40.94 and 43. This is the way how I approached it. With contourtable I acquired the (x,y) coordinates of the contourlines.
muSP = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9];
muRP = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9];
[X,Y] = meshgrid(muSP,muRP);
Z = cell2mat(reshape(AoR_mean,[9,9]));
[C,h] = contour(X,Y,Z,(40.9431:2.0538:42.9969));
hold on
title('Angle of Repose - Ledge Test 2D');
xlabel('\mu_s')
ylabel('\mu_r')
clabel(C,h,'LabelSpacing',500,'FontSize',8);
h.LevelList = round(h.LevelList,2);
set(gca,'XTick',0.1:0.1:0.9,'XTickLabel',0.1:0.1:0.9,'XTickLabelRotation',45);
set(gca,'YTick',0.1:0.1:0.9,'YTickLabel',0.1:0.1:0.9);
grid on
% Extract x- and y-coordinates of contour lines
contourTable = getContourLineCoordinates(h);
% Define grid for the variable space
N1 = 80;
muRP_grid = linspace(0.1,0.9,N1);
muSP_grid = linspace(0.1,0.9,N1);
[R,S] = meshgrid(muRP_grid,muSP_grid);
plot(R,S,'.r');
hold off
% x- and y-coordinates of polygon vertices, i.e. between AoR of 40.11 degrees
% and AoR of 43.83 degrees
xv = table2array(contourTable(1:31,3));
yv = table2array(contourTable(1:31,4));
inside_variablespace = inpolygon(R,S,xv,yv);
% x- and y-coordinates corresponding to the discretized points in the
% variable spac
xcoord = R(inside_variablespace);
ycoord = S(inside_variablespace);
However, for some reason I don't get de discretized points within the boundaries 40.94 and 43.

Best Answer

Read about inpolygon. If you have a polygon and a set of points, you cann extract the points lying inside this polygon using that.