help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Counting around number


From: Martin Helm
Subject: Re: Counting around number
Date: Sun, 28 Nov 2010 22:38:48 +0100
User-agent: KMail/1.13.5 (Linux/2.6.34.7-0.5-desktop; KDE/4.5.3; x86_64; ; )

Am Sonntag, 28. November 2010, 22:16:04 schrieb Isak Delberth Davids:
> if (b(i) >= b(i)-bin_size || b(i) < b(i)+bin_size);

You have a logical error I think, to check if the number is in the intervall 
it should be && not ||

if (b(j) >= b(i)-bin_size && b(j) < b(i)+bin_size)

Second thing is the ; after the If () makes no sense.
Third it needs to be b(j) not b(i) which you check.

Fourth you can avoid at least one  loop by recognising that

sum(abs(b - b(i) < bin_size))

gives you the number of elements with maximum bin_size distance from the b(i) 
(you nedd to subtract 1 if you don't want to count the element b(i) itself)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]