[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: |
Mon, 29 Nov 2010 00:20:13 +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, 23:16:47 schrieb Isak Delberth Davids:
> On 28 November 2010 23:41, Martin Helm <address@hidden> wrote:
> > Am Sonntag, 28. November 2010, 22:38:48 schrieb Martin Helm:
> > > sum(abs(b - b(i) < bin_size))
> >
> > Sorry a typo, it should be
> >
> > sum ( abs (b-b(i)) < bin_size )
>
> OK, I see Martin, I am digesting your suggestions. By the way, how
> different is all this from using a hist as in the following case. I seem
> not to like the way the plot displays random lines, I would like to join
> the points in increasing order of the x-values, and not in the order that
> the x-values appear in the array b:
>
> I failed to use
>
> > sum ( abs (b-b(i)) < bin_size )
>
> in order to reduce my loops --- will still try. Despite that, this is what
> I have now.
> ___________________________
> clear;clc;
> a = rand(100,1)*0.1; % something array to work with
> bin_size = 0.01; % size around numbers
> b = a.* exp(-a.^2);
> event_counter = zeros(length(b),1);
> for i = 1:length(b);
> for j = 1:length(b);
> if (b(j) >= b(i)-bin_size && b(j) < b(i)+bin_size) % binning
> event_counter(j)++;
> end
> end
> end
> plot(b,event_counter)
>
> and does the hist function below do exactly the same thing?
> ___________________________
>
> clear;clc;
> a = rand(100,1)*0.1; % something array to work with
> bin_size = 0.001; % size around numbers
> b = a.* exp(-a.^2);
> c = 0:bin_size:max(b);
> figure(1)
> hist(b,c)
>
> Cheers,
> IDD
> * * * * * * * * * * * * * * *
> * Isak Delbert Davids *
> * +264-81-33 049 33 *
> * +264-61-206 3789 *
> * Namibia, Afrika *
> * * * * * * * * * * * * * * *
You need to sort the entries in b and then to apply the same rearrangements to
your vector event_counter
clear;clc;
a = rand(100,1)*0.1; % something array to work with
bin_size = 0.01; % size around numbers
b = a.* exp(-a.^2);
event_counter = zeros(length(b),1);
for i = 1:length(b);
event_counter(i) = sum ( abs (b-b(i)) < bin_size );
end
[S, I] = sort (b);
plot(S,event_counter(I))
It is very similar to hist (btw I would probably use hist anyway)
Please don't forget to keep the list on cc