将单个数组的元素排序为不同的子数组

时间:2013-09-02 18:44:50

标签: arrays matlab

我有一个1000个元素的数组,其值介于1 - 120之间。我想将此数组拆分为6个不同的子数组,相对于值范围

代表:

  

array1,其值范围为0-20。

     

数组2,其值范围为20-40 ........ 100-120等。

最后,我想绘制一个以X轴为范围的直方图,每个条形图描绘该范围内的元素数量。我不知道“这种”绘图的任何其他方式。

由于

2 个答案:

答案 0 :(得分:2)

换句话说,您想要创建直方图。 Matlab的hist()会为你做这件事。

答案 1 :(得分:0)

如果您只需要直方图,则可以使用histc来实现结果,如下所示:

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