Removing rows from arrays in cells using indexing

If I have a cell containing points necessary to create multiple polygons, like this
A = {[2,1; 3,1; 3,3; 4,3; 2,1],[4,1; 5,1; 5,3; 4,3; 4,1]}
A =
1×2 cell array
[5×2 double] [5×2 double]
And a separate matrix containing a bounding polygon
B = [1,2; 7,2; 7,7; 1,7; 1,2];
I want to remove all points in cell A that lie within the bounding polygon,B. I have a cell that identifies all the points within the bounding polygon B, now how do I remove those points from cell A?
idx = {[0; 0; 1; 1; 0],[0; 0; 1; 1; 0]};

 Accepted Answer

result = cellfun(@(x,y)x(~y,:),A,idx,'uni',false);

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!