MATLAB: Random values from histogram

MATLABrand

Hi
how i can use one value at the time from histogram and after use that value is deleted and i cannot use that again eg. if i have
x=rand(1,100)
[N,X]=hist(x,15)
bar(X,N,1,'w')
i want to get 100 values one by one
Thanks a lot

Best Answer

Standing on the shoulder of a giant WR, the following run-length based code will create a random list of 10 values that are derived from the results of a histogram
% simplified example
% data obtained by hist
X = [.1 .4 .6 .8] ; % possible values
N = [5 3 0 2] ; % how many times the occurred
% a simple but effective run-length decoding scheme
clear ix ;
ix([1 cumsum(N(1:end))+1]) = 1 ;
ix = cumsum(ix(1:end-1)) ;
% retrieve the values
X2 = X(N>0) ;
V = X2(ix) ; % all 10 values
RandV = V(randperm(numel(V))) % in random order