2
votes

I've got a 20x65536 matrix M filled with integers of the range [0,14].

For each column of M I want to create a histogram with 14 bins. In total, I would have 65536 histograms.

Afterward, I would like to combine all of these histograms into one 3d-like histogram, with the x-axis being the 15 bins, the y-axis the 65536 histogram indices and the z-axis the number of the occurences of the corresponding bin.

3
You mean 15 bins, right?A. Donda
Of course, you are right!Richard Laurant

3 Answers

3
votes

Try this:

surf(histc(M, 0:14, 2))
1
votes

This should do what you are looking for:

% compute histograms
bins = 0 : 14;
count = hist(M, bins);

% plot as three-dimensional bar plot
bar3(bins, count)

However, doing this for a matrix with 65536 columns is not a good idea, since a normal computer screen can show about 2000 pixels horizontally. Here is how it looks like for a matrix with 25 columns:

enter image description here

To make the axis better fit the bin values, use

ylim([-1 15])
0
votes

use imagesc to get a color image, where the color of each (x,y) is the number of counts in that bin for that histogram.

Mnew = histc(M,0:14,1);
imagesc(Mnew)
set(gca,'YDir','normal')

The last line is just to fix a nuance of imagesc, that it flips the y-axis.