help-octave
[Top][All Lists]
Advanced

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

Counting around number


From: Isak Delberth Davids
Subject: Counting around number
Date: Sun, 28 Nov 2010 23:16:04 +0200

Hi all,

the code below is meant to count values within close range of each number in an array. I want to work with the array "b" as constructed below. So what I want is the following: I want to see how many values (thus a count called "event_counter") are there around (distance "bin_size" away) each of my numbers in "b". While hoping that I made myself clear, I am sure something is wrong with my approach --- I get a horizontal line!. Where am I messing up?

clear;clc;
a = rand(100,1)*0.1; % some numbers
bin_size = 0.001; % size around numbers
b = a.* exp(-a.^2); % to get a set of well-behaved numbers
event_counter = zeros(length(b),1);
for i = 1:length(b);
    for j = 1:length(b);
        if (b(i) >= b(i)-bin_size || b(i) < b(i)+bin_size);
            event_counter(j)++;
        end
    end
end

plot(b,event_counter)

Cheers,
           ID
 
* * * * * * * * * * * * * * *
*  Isak Delbert Davids *
*  +264-81-33 049 33  *
*  +264-61-206 3789   *
*    Namibia, Afrika     *
* * * * * * * * * * * * * * *


reply via email to

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