how to give probability of 90% to unique values of a vector and 10% to repeated values?

Hello, how can I give 90% probability to elements of a vector that do not repeat themselves, and to elements that repeat 10%.
for example:
I have a vector
vector = [10 15 15 23 20 40]
give a probability of 90% to the numbers 10,23,20,40, and a probability of 10% to the numbers that are repeated, that is, 15,15.
and store it in a variable
thanks in advance

2 件のコメント

Rik
Rik 2021 年 12 月 15 日
Have you already found a way to separate those two groups of numbers? That seems the first step to me. Then you can sample them in a 1:9 ratio.
separate them in what way?
vector = [10 23 20 40 15 15]
like that?

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

 採用された回答

Did you try a simple for loop?
vector = [10 15 15 23 20 40];
probabilities = zeros(1, length(vector));
for k = 1 : length(vector)
if sum(vector == vector(k)) >= 2
% Repeated
probabilities(k) = 0.1;
else
% Not repeated
probabilities(k) = 0.9;
end
end
probabilities % Show in command window.
probabilities = 1×6
0.9000 0.1000 0.1000 0.9000 0.9000 0.9000

5 件のコメント

hi, i had a problem with your code.
when I put this vector with allocated.mat (attached) list.
I get the following
Operator '==' is not supported for operands of type 'cell'.
Error in MSG3 (line 33)
if sum (allocated == allocated (k))> = 2
you can help?
OK, this is what I got:
s = load('allocated.mat')
allocated = s.allocated
for k = 1 : length(allocated)
Preambulo(k) = allocated{k}.Preambulo;
TA(k) = allocated{k}.TA;
Prb(k) = allocated{k}.Prb;
end
but I don't know which of these new variables are the variables "vector" and "probabilities" that we were using before.
you're right I'm very sorry.
the vector variable would be the Preambulo variable.
But with the information you just gave me, I managed to make the code work, thank you.
Image Analyst
Image Analyst 2021 年 12 月 22 日
Oh, OK, great! You're welcome. Thanks for Accepting my Answer. 😃
Hello my friend how are you? I hope it's ok.
could you help me with this question? https://la.mathworks.com/matlabcentral/answers/1652655-how-can-i-choose-non-repeating-values-with-a-probability-of-90-and-10
is very similar to this question
Thanks in advance

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

その他の回答 (0 件)

カテゴリ

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

製品

リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by