how to give probability of 90% to unique values of a vector and 10% to repeated values?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
giancarlo maldonado cardenas
am 15 Dez. 2021
Kommentiert: giancarlo maldonado cardenas
am 18 Feb. 2022
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 Kommentare
Rik
am 15 Dez. 2021
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.
Akzeptierte Antwort
Image Analyst
am 15 Dez. 2021
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.
5 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!