tl;dr:
x = [ 0.1576, 0.9706, 0.9572, 0.4854, 0.8003, 0.1419, 0.4218, 0.9157, 0.7922, 0.9595 ]
[ ~, Bins ] = histc( x, 0: 0.25: 1 )
% Bins = 1 4 4 2 4 1 2 4 4 4
Explanation:
According to the matlab manual:
Earlier versions of MATLABĀ® use the hist and histc functions as the primary way to create histograms and calculate histogram bin counts [...] The use of hist and histc in new code is discouraged [...] histogram, histcounts, and discretize are the recommended histogram creation and computation functions for new code.
and
The behavior of discretize is similar to that of the histcounts function. Use histcounts to find the number of elements in each bin. On the other hand, use discretize to find which bin each element belongs to (without counting).
Octave has not yet implemented discretize, but still supports histc, which as the above implies, does the same thing but with a different interface.
According to the octave documentation of histc
-- [N, IDX] = histc ( X, EDGES )
Compute histogram counts.
[...]
When a second output argument is requested an index matrix is also
returned. The IDX matrix has the same size as X. Each element of
IDX contains the index of the histogram bin in which the
corresponding element of X was counted.
Therefore the answer to your problem is
[ ~, Bins ] = histc( x, 0:0.25:1 )
Using your example:
x = [ 0.1576, 0.9706, 0.9572, 0.4854, 0.8003, 0.1419, 0.4218, 0.9157, 0.7922, 0.9595 ]
[ ~, Bins ] = histc( x, 0: 0.25: 1 )
% Bins = 1 4 4 2 4 1 2 4 4 4
PS. If you like the interface provided by discretize, you can easily create this function by yourself, by wrapping histc appropriately:
discretize = @(X, EDGES) nthargout( 2, @histc, X, EDGES )
You can now use this discretize function directly as in your example.