Azzera filtri
Azzera filtri

pre allocating / extracting data from vector based on condition

3 visualizzazioni (ultimi 30 giorni)
לק"י
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 Commenti
Jan
Jan il 10 Feb 2023
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 il 11 Feb 2023
לק"י
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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Voronoi Diagram in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by