Categorising coordinates into a table

Say I have cell column C of size (n,1), and in each entry are two row vectors A_i and B_i (for i=1,2,...,n) of the same length m which contain numbers. I want to create a table of the data according to which we scan each pair of vectors A_i and B_i and categorise them into the ranges Arange=[0,1,3,5,7,9,999] and Brange=[0,2,4,6,8,10,999], . So if A_3=4 and B_3=12, it would go into the table position (6,3). Ideally, each entry in the table would be a list of coordinates which I can use to get the total number of elements that fit into that particular coordinate in the table.
I can calculate the totals in a range for just one row vector A_i and one range Arange as shown in the attachment, but how I do extend this to two vectors and two ranges, and to get a list of coordinates rather than just the number of coordinates?
EDIT: attaching new file of data.

4 个评论

Sounds like a binning problem from the choice of words but I can't quite make out what the actual input looks like nor the desired output...attach a small(ish) dataset that illustrates both inputs and the desired output(s)...
Thanks, I have attached a new file R2.m with a small dataset. It's just categorising some coordinates into row bins and column bins.
>> cell2mat(C)
ans =
5.7000 2.9000 6.5000
1.1000 3.6000 2.8000
5.8000 0.5000 2.8000
7.4000 1.6000 0.8000
>> Arange=[0,1,3,999];
Brange=[0,2,4,999];
>> [Arange; Brange]
ans =
0 1 3 999
0 2 4 999
>> want=[1 1 1; 0 1 1; 0 0 1]
want =
1 1 1
0 1 1
0 0 1
>>
'Splain how you get want from the above dataset? C(1,1) (as well as several other elements) is greater than the bin limits shown. What does want really represent in your mind?
Thanks. Guillaume seems to have answered my question below.

请先登录,再进行评论。

 采纳的回答

Is there any reason to store your data as a cell array instead of a 3D matrix (or two 2D matrices) which would make your life simpler?
Is the 999 in your bin description supposed to be a value always greater than the max of the vectors, just to say that the last bin includes everything above the previous number? If so, use Inf instead.
I'm with dpb, I'm not very clear what you're after. If want is the histogram of the values, then it appears to be a 180 degree rotation of the true histogram:
C = {[5.7 2.9 6.5; 1.1 3.6 2.8]; [5.8 0.5 2.8; 7.4 1.6 0.8]};
%first transform that akward cell array in something easier to manipulate, e.g. a 3D matrix:
moreuseful = cat(3, C{:}); %so the A vectors are moreuseful(1, :, :), the B vectors are moreuseful(2, :, :).
%then build the histogram
Arange = [0,1,3, Inf];
Brange=[0,2,4, Inf];
h = histcounts2(moreuseful(1, :, :), moreuseful(2, :, :), Arange, Brange)
result is in
h =
1 0 0
1 1 0
1 1 1

更多回答(0 个)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by