Random values from histogram

3 ビュー (過去 30 日間)
niko kauppinen
niko kauppinen 2011 年 2 月 8 日
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
  2 件のコメント
Oleg Komarov
Oleg Komarov 2011 年 2 月 8 日
I don't understand what are you asking.
niko kauppinen
niko kauppinen 2011 年 2 月 8 日
sorry I did not asked correctly.
I want to know if I have eg, Radius of something let's say 2-5,and there is different radius 2,3,2,4,5,5,....and so on. and i have PDF of them how i can choose first one of them and after my loop coming back i choose second one and so on....

サインインしてコメントする。

採用された回答

Jos (10584)
Jos (10584) 2011 年 2 月 11 日
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

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 2 月 8 日
Okay, then, what this is equivalent to is taking each bar count as a run-length encoding of the value associated with that bar (e.g., the bar center), then doing a randperm() of that expanded vector.
I know a couple of people have posted efficient run-length decoding routines; I just don't happen to remember one at the moment.

Walter Roberson
Walter Roberson 2011 年 2 月 8 日
x(randperm(1:length(x))
The histogram becomes irrelevant. Each item will occur exactly the number of times it did in the original list.
  3 件のコメント
Walter Roberson
Walter Roberson 2011 年 2 月 8 日
Hmmm... the bar _counts_ are what are to be chosen from, perhaps? But if so then should the bar count decrease one one of the items from that bar is "used up", or should the bar count itself stay the same but the number of repetitions of it "available" decreases?
Or perhaps it is the bar _index_ that needs to be chosen randomly, in accordance with the counts?
niko kauppinen
niko kauppinen 2011 年 2 月 8 日
yes i choose from bar count or PDF and it should decrease one
you are right
can you help me?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by