pre allocating / extracting data from vector based on condition

조회 수: 3 (최근 30일)
Amit Ifrach
Amit Ifrach 2023년 2월 9일
댓글: Amit Ifrach 2023년 2월 11일
לק"י
Hello!
I want to find a way other then if statement to go through vector and check if some conditions apply to each cell and to return 1 or 0 in accordance to the result of the conditions.
for example, I have a vector called vorroi, which contains the candidate points to be ploted in a plot.
the current process that decides if the current cell of vorroi will be plottted (passed the statements) is this for statement:
if ismember(1, c{j})==0 && (isempty(polyxpoly(crsvrtcl(:,1),crsvrtcl(:,2),v(c{j},1),v(c{j},2)))==0 || isempty(polyxpoly(crshrzntl(:,1),crshrzntl(:,2),v(c{j},1),v(c{j},2)))==0) %ismember(0, inpolygon(v(c{j},1),v(c{j},2), fhpos(:,1), fhpos(:,2)))~=1
which asks if the candidate point voronoi *(some background about voronoi in the end) area is inf (ismember(1, c{j})), and if it crosses one of two lines I draw (isempty statements).
It would be very beneficial to compute the result of the if statement without the need to fo through that loop. is it possible? and how?
I tried several attempts, such as:
plgnsinmrkd=[vorroi(ismember(1, c{vorroi(:,1)})==0 && (isempty(polyxpoly(crsvrtcl(:,1),crsvrtcl(:,2),v(c{vorroi(:,1)},1),v(c{vorroi(:,1)},2)))==0 || isempty(polyxpoly(crshrzntl(:,1),crshrzntl(:,2),v(c{vorroi(:,1)},1),v(c{vorroi(:,1)},2)))==0))];
plgnsinmrkd=vorroi(ismember(1, c{vorroi(:,1)})==0 && (isempty(polyxpoly(crsvrtcl(:,1),crsvrtcl(:,2),v(c{vorroi(:,1)},1),v(c{vorroi(:,1)},2)))==0 || isempty(polyxpoly(crshrzntl(:,1),crshrzntl(:,2),v(c{vorroi(:,1)},1),v(c{vorroi(:,1)},2)))==0));
plgnsinmrkd=(vorroi(ismember(1, c{vorroi(:,1)})==0 && (isempty(polyxpoly(crsvrtcl(:,1),crsvrtcl(:,2),v(c{vorroi(:,1)},1),v(c{vorroi(:,1)},2)))==0 || isempty(polyxpoly(crshrzntl(:,1),crshrzntl(:,2),v(c{vorroi(:,1)},1),v(c{vorroi(:,1)},2)))==0)));
and it didn't do it, the output is:
> plgnsinmrkd=(vorroi(ismember(1, c{vorroi(:,1)})==0 && (isempty(polyxpoly(crsvrtcl(:,1),crsvrtcl(:,2),v(c{vorroi(:,1)},1),v(c{vorroi(:,1)},2)))==0 || isempty(polyxpoly(crshrzntl(:,1),crshrzntl(:,2),v(c{vorroi(:,1)},1),v(c{vorroi(:,1)},2)))==0)));
>> plgnsinmrkd
plgnsinmrkd =
[]
I thiought it would be something like other line I wrote:
datintmrkd=(cell2mat(dat(:,3))>minint(m) & maxint(m)>cell2mat(dat(:,3))); %create a vector that assings 1 to coresponding cell within data only if in minint and maxint range.
but somewhy it doesn't work.
Sorry for all the questions lately, and thank you all!
Amit.
*A little background - Voronoin gives back 2 vectors, v and c that are the (x and y points of the vertices - v vector) and (index of vertices which relate to each polygon created in the voronoi - c vector). more info here: N-D Voronoi diagram - MATLAB voronoin (mathworks.com).
  댓글 수: 4
Jan
Jan 2023년 2월 10일
Sorry, this is far too extensive for a question in the forum. Split the problem into parts. If a question can be understood in less then 2 minutes, it has much higher chances to get an answer. Maybe this helps: https://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer .
Amit Ifrach
Amit Ifrach 2023년 2월 11일
לק"י
Hi Jan, thanks for the tip. I deconstructed it to some basic questions as you said. hope it would be easier to understand then.
Have a great week and thanks for everything!
Amit.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Voronoi Diagram에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by