How do I specify the frequencies for a 3D histogram?
Show older comments
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)
Steven Lord
on 13 Oct 2016
0 votes
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
Juan Martínez
on 13 Oct 2016
Steven Lord
on 13 Oct 2016
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.
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!