|
"Rhys " <rhyswork@yahoo.co.uk> wrote in message <htm1jb$5bf$1@fred.mathworks.com>...
> Ive been playing with histc and accumarray, but think they will not do this.
>
> Is there an easy way to bin data in non-monotonic, unevenly distributed bins
>
> I want to count the number of ones in data(:,1) into bins defined by data(:,2). A snippet of real data is below.
>
> So the question is, for the data below, count how many ones there are for 135045, for 135225, etc.
>
> any ideas, or is a relable of the bins in order, so they are monotonic, then accumarray or histc?
>
> data = [1 135045
> 1 135225
> 1 45135
> 0 135225
> 0 45135
> 1 45315
> 0 135225
> 0 315045
> 1 315045
> 1 225315
> 1 135045
> 0 135225
> 0 135045
> 0 135045
> 1 225135
> 1 315225
> 1 315225
> 0 45315
> 0 315225
> 1 45135
> 0 225135
> 0 45135
> 1 315045
> 1 315045
> 1 45135
> 1 45315
> 0 45315
> 1 225135
> 1 225315
> 1 135045
> 0 135225
> 0 315225
> 1 225135
> 1 225315
> 1 225135
> 1 315045
> 1 315225
> 0 45315]
data = [1 135045
1 135225
1 45135
0 135225
0 45135
1 45315
0 135225
0 315045
1 315045
1 225315
1 135045
0 135225
0 135045
0 135045
1 225135
1 315225
1 315225
0 45315
0 315225
1 45135
0 225135
0 45135
1 315045
1 315045
1 45135
1 45315
0 45315
1 225135
1 225315
1 135045
0 135225
0 315225
1 225135
1 225315
1 225135
1 315045
1 315225
0 45315];
[udata, trash, ix] = unique(data(:,2));
A = accumarray(ix,data(:,1));
results = [udata, A];
|