split_vector_into_equal_sized_bins( input_vect , N_per_bin )
bins_idx = split_vector_into_equal_sized_bins( input_vect , N_per_bin )
given a vector
split into equal sized bins w/ N_per_bin elements in each bin
returns the bin of each element
the diff w/discretize() is that discretize() makes bins of even width
(range) while split_vector_into_equal_sized_bins() makes bins of equal #
of elements
to see the difference:
X = random('normal',10,1,1e4,1);
discIDX = discretize( X , 100 );
binsIDX = split_vector_into_equal_sized_bins( X , numel(X)/100 ) ;
figure ; hold on;
boxplot(X,binsIDX,'Color','r')
boxplot(X,discIDX,'Color','b')
warning('off','split_vector_into_equal_sized_bins:unevenbins') % to disable warnings
LBC lucas.carey@upf.edu April 2017
Cite As
Lucas Carey (2026). split_vector_into_equal_sized_bins( input_vect , N_per_bin ) (https://www.mathworks.com/matlabcentral/fileexchange/62556-split_vector_into_equal_sized_bins-input_vect-n_per_bin), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 2.111.0.0 | typo |
||
| 2.11.0.0 | forgot to update file |
||
| 2.1.0.0 | (1) output vector is the same shape as input vector
|
||
| 2.0.0.0 | Jos correctly points out this is 10x faster than the original code |
||
| 1.0.0.0 |
