How to compare either one value is closer to some other values?

3 views (last 30 days)
For example, I have an image containing lines. A line with SLOPE = 50 degree, if any other line is between 45-55 degree of SLOPE (say 48,53), I wanna merge those line. (I mean, merge the line with closer/ nearer slope). I have a matrix with slopes of all line in the image SLOPE(20*1) of class double. I am trying by stating
if (SLOPE(a) >= SLOPE(:,1) - 5 || SLOPE(a) <= SLOPE(:,1) + 5)
dataset(a) = dataset(a) + dataset of those that match if condition
end
Don't get confidence, this inequality is defined properly? say, dataset is (x,y) location of that lines. How can I write the 2nd line of the code? SLOPE of a particular line could be equal to none, some, or all of them.

Accepted Answer

dpb
dpb on 9 Apr 2015
Use histc with the EDGES input the boundaries between desired bins; in your example it would be
[~,ix]=histc(SLOPE,[-inf 45 55+eps inf]);
Then
SLOPES(ix==2)
is the elements between 45-55, inclusive. NB: the use of +eps on the upper bound of the range; by default histc use >=X< as the range so must modify a little to get the inclusive upper bound.

More Answers (0)

Categories

Find more on Multidimensional Arrays 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!