I have a vector [4,5,6] and I want to have each element with probability 1/3. I need it for a SDP model.

回答 (1 件)

Adam Danz
Adam Danz 2021 年 5 月 3 日
編集済み: Adam Danz 2021 年 5 月 5 日

1 投票

If there's a uniform probability of selecting any element of a vector, use randi as shown below.
x = [4 5 6];
n = 10000; % number of random selections
y = x(randi(numel(x),1,n));
% Look at probability distribution
histogram(y,'Normalization','probability')
yline(1/numel(x),'m-',sprintf('%.2f',1/numel(x)),'LineWidth',2)
ylim([0,1])

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

質問済み:

2021 年 5 月 3 日

編集済み:

2021 年 5 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by