MATLAB Answers

Can anyone help me in this code ?

1 view (last 30 days)
L K on 15 Mar 2017
Commented: L K on 16 Mar 2017
%To Calculate the points which lie inside and outside Tolerance
[in,on] = inpolygon(real,imag,xch_larger,ych_larger);
i want a msg to be displayed when r>=0
i have put this statement
if r >= 0;
msgbox('So-n-so','Detected Object','error');
msgbox('So-n-so','Detected Object');
But the problem i am facing is, even if the value is r<=0 Still it displays the first msg, it does not go in the else part... what is problem ?

Accepted Answer

Guillaume on 15 Mar 2017
Edited: Guillaume on 15 Mar 2017
I strongly suspect that you want the number of query points in, on and outside the polygon, which you'll never get with numel (See comment to Image Analyst's answer). I suspect this is what you want:
p = sum(in); %number of points inside or on the polygon
q = sum(on); %number of points on the polygon
r = sum(~in); %number of points outside the polygon
L K on 16 Mar 2017
Thanx for the valuable info :) I did the changes

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 15 Mar 2017
numel() returns the number of elements in an array. Why do you think that should EVER be negative?
Guillaume on 15 Mar 2017
And since in and on are logical arrays, all those real(something) are also completely pointless.
And since in and ~in obviously have the same numbers of elements, p and r will always be equal.
"and the other condition would be true when r=0"
And since the number of elements in in and on is the same as the number of elements in the input, the only way that r can be 0 is if you pass zero query points.
Really, the problem is not with the if but with everything that is before!

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!