Generating random number from a given sequence.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Aftab Ahmed Khan
am 25 Jul. 2016
Beantwortet: Steven Lord
am 25 Jul. 2016
Hello, I am generating a random sequence of channels one after another based on its availability. The way i'm doing it is like this. It is working fine but i don't like the way i have implemented it. Can you suggest a more efficient method for doing the same thing. Thank you.
idle=0;
ava_channelsabs=find(channelstate_abs(idabs,abs_idbeam,:)==idle);
col_slot1=[];
while length(col_slot1)<length(ava_channelsabs)
rand_slot1=randi(length(ava_channelsabs),1,1);
check=ismember(rand_slot1,col_slot1);
if check==0
rand_channel1=ava_channelsabs(rand_slot1);
col_slot1=[col_slot1,rand_slot1];
end
end
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 25 Jul. 2016
It sounds like you want to perform sampling without replacement. If that's the case take a look at the randperm function.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!