4 views (last 30 days)

Adam Danz
on 14 Nov 2019

Edited: Adam Danz
on 14 Nov 2019

What you're describing sounds like a bar chart rather than a histogram. 1000 bars is quite a lot of bars.

data = logical(randi(2,100,100,100)-1); % Fake data (100 x 100 x 100)

count = squeeze(sum(data,[1,2])); % Number of TRUE in each layer (3rd dimension)

bar(count) % The bar plot

If you'd like to use the histogram function instead: histogram('BinEdges',edges,'BinCounts',counts)

histogram('BinEdges',1:101,'BinCounts',count)

% 1:1001 in your case

How do bins in histograms work?

Suppose you have a bunch of random data between 0 and 100 and you want to know how many values there are between 0:5, 5:10, 10:15, ..., 95:100. The histogram function (or the histcounts function) will sort your data into those bins and count the number of points within each bin.

In your case, you're not really working with bins. You want to know the number of 1-values on each layer of your 3D array. If you ask the histrogram function for 1000 bins, it will see that your data (the 1-counts) range from 0 to 10^5 and it will divide that range into 1000 parts. That's not what you want. You already know the "bins" (1,2,3,...,1000, which aren't really bins). Does that make more sense?

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.