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