complex logical indexing?
Show older comments
לק"י
Hello!
lets assume I want to logically index a vector, or create a new vector that will hold the results of these logical indexing and it's complex as follow:
A - Vector that contain the index (1, 2, 3, 4, etc.) of areas (not the areas themeself, like 1.243, 2, 453.345 etc).
B - Cell array that contains numerical data in each cell (for example, {1, 25, 33, 15}) of indexes of another vector C.
C - Vector that contain 2 columns (x and y points) of a vertices, the first C(:,1) the X points of the vertices, C(:,2) the Y points of the vertices.
D - Vector that contain 2 columns (x and y points) of a vertical line, the first D(:,1) the X points of the vertical line, D(:,2) the Y points of the vertical line.
E - Vector that contain 2 columns (x and y points) of a horizontal line, the first E(:,1) the X points of the horizontal line, E(:,2) the Y points of the horizontal line.
I wish to find all the coresponding indexes in A that:
corresponding cell index in cell array B won't contain the number '1'. (so if B(1) = {1,2,25,33,56,123} it will give back a 0)
AND
areas correspond to the index of A and cross one of the two lines C and D (vertical or horizontal).
I know the conditios that do it are:
ismember(1, B{j})==0 && (isempty(polyxpoly(D(:,1),D(:,2),C(B{j},1),C(B{j},2)))==0 || isempty(polyxpoly(E(:,1),E(:,2),C(B{j},1),C(B{j},2)))==0)
I can do it with for loop such as:
for j=1
if ismember(1, B{j})==0 && (isempty(polyxpoly(D(:,1),D(:,2),C(B{j},1),C(B{j},2)))==0 || isempty(polyxpoly(E(:,1),E(:,2),C(B{j},1),C(B{j},2)))==0)
end
But I would be much faster and easier to somehow skip the loop.
Thanks (Jan?)!
Amit.
3 Comments
I try to onvert the text description to explicit code:
A = 1:33;
B = {1, 25, 33, 15};
C = rand(33, 2);
D = rand(33, 2);
E = rand(33, 2);
"corresponding cell index in cell array B won't contain the number '1'. (so if c(1) = {1,2,25,33,56,123} it will give back a 0)" - What is c(1) = {1,2,25,33,56,123} ? A lower case "c" did not appear before.
Anyway, to exclude cells containing a 1:
any([c{:}] == 1)
"areas correspond to the index of A and cross one of the two lines C and D (vertical or horizontal)." - I have only a faint idea of what this means.
I'd expect B{j} ~= 1 to be much faster than ismember(1, B{j})==0 .
I suggest, you improve my guessed example code. Then we get a step nearer to a solution.
Don't let my numerous questions for clarification confuse you. Finding a completely clear formulation of a question is almost the full way to get a solution. Of course this is omplicated. Otherwise the problem would be trivial :-)
Amit Ifrach
on 11 Feb 2023
Bruno Luong
on 6 Mar 2023
Edited: Bruno Luong
on 6 Mar 2023
@Amit Ifrach "areas correspond to the index of A and cross one of the two lines C and D (vertical or horizontal)"
Using polyxpoly to check a Voronoi cell crossing vertical and horizontal is overkill, it is enough to check the x or y coordinates are in both sides of the line vertical or horizontal coordinates.
Accepted Answer
More Answers (0)
Categories
Find more on Voronoi Diagram in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
