Categorising coordinates into a table

5 views (last 30 days)
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 Comments
dpb
dpb on 11 Feb 2019
>> 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?
Sam Smith
Sam Smith on 11 Feb 2019
Thanks. Guillaume seems to have answered my question below.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 11 Feb 2019
Edited: Guillaume on 11 Feb 2019
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

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!