How to make a certain percentage of values in an existing matrix, between a set range of values. Probably easy but I am a newbie.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kelley Kehoe
am 3 Okt. 2020
Beantwortet: Rub Ron
am 3 Okt. 2020
size=[25,10];
Score=randi([50,100],size);
So I have these commands in my script to create a 25x10 matrix of randomly assigned values between 50 and 100. However I need to make 10% of those randomly assigned values between 30 and 50, with the ability to change the percentage at will. Any help would be great.
0 Kommentare
Akzeptierte Antwort
Rub Ron
am 3 Okt. 2020
What about this:
size=[25,10];
Score=randi([50,100],size);
my_percentage = 10;
my_piece = prod(size)*my_percentage/100;
sub_score=randi([30,50],[1, my_piece]);
rand_idx = randperm(prod(size),my_piece);
Score(rand_idx)=sub_score;
0 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!