How do I specify the frequencies for a 3D histogram?

Hi everyone,
I want to plot a 3D histogram and I am using the histogram2 function. My problem is that I have my data in a matrix with 3 columns: the two first columns are the paired values and the third column contains the number of times that each combination appears
mat=[4 5 2; 7 8 3; 6 9 1; 4 3 2; ... ] (see example in table)
In the example you can see that there are 2 students who got 4 in maths and 5 in science at the same time, 3 students who got 7 and 8, etc.
When I use histogram2 I cannot tell the function how many students got each paired marks. I have thought of building a new matrix that contains one row for each repetition: [4 5; 4 5; 7 8; 7 8; 7 8; 6 9; 4 3; 4 3], but the problem is that my real data are too big (3.5 million rows) and the absolute frequencies are too high (around 4000 times each row). So, the new matrix becomes a 10^10 x 2 matrix, and my matlab version cannot create such a huge matrix.
Does somebody have any ideas of how I can do this?
Thanks a lot,
Juan Martinez

Answers (1)

In release R2016b both histogram and histogram2 have the option to accept bin counts directly via the BinCounts parameter. You can specify this instead of specifying raw data to be binned.

2 Comments

Thanks for answering Steve.
I have seen that option, but my problem is that I can only use that if instead of introducing my data, I specify the edges of the bins. This would be an option but I would have to process all the data before and generate the matrix with the absolute frequencies. Since I have 3.5 millions of rows, I would like to know if there is any other way of doing this.
Thanks in advance,
Juan
If you have 3.5 million rows, assuming that the grades for each subject have the same range, your grades must go from about 0 to 1870? Otherwise you'd have duplicates that you should combine, like a row that says 5 students received marks of [4 5] and another row that says 7 students received marks of [4 5].
If you do have duplicates, consider using accumarray to consolidate the duplicates. The first two columns of your data will be the SUBS input, the third column the VAL input.

Sign in to comment.

Asked:

on 13 Oct 2016

Commented:

on 13 Oct 2016

Community Treasure Hunt

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

Start Hunting!