0

I have an 1000 element array with values ranging from 1 - 120. I want to split this array into 6 different subarrays with respect to the value range

for ex:

array1 with values from ranges 0-20.

array 2 with values from range 20-40........100-120 etc.

At the end I would like to plot a histogram with X-axis as the range and each bar depicting the number of elements in that range. I dont know of any other way for 'this' kind of plotting.

Thanks

1
  • What were your attempts to do that? could you show us some code? Commented Sep 2, 2013 at 18:49

2 Answers 2

2

In other words, you want to create a histogram. Matlab's hist() will do this for you.

Sign up to request clarification or add additional context in comments.

Comments

0

If you only need the histogram, you can achieve the result using histc, like this:

edges = 0:20:120; % edges to compute histogram
n = histc(array,edges); 
n = n(1:end-1); % remove last (no needed in your case; see "histc" doc)
bar(edges(1:end-1)+diff(edges)/2, n); % do the plot. For x axis use
% mean value of each bin

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.