Generate a rondom sequence

조회 수: 9 (최근 30일)
abdulhakeem
abdulhakeem 2013년 3월 15일
Greetings,
Please can any one help me about:
How to Generate Generate a random sequence Z ={(i, j)},
where i, j Belongs to {1, 2, 3, 4}, i not equal to j
i and j are selected randomly.
Best Regards

채택된 답변

Youssef  Khmou
Youssef Khmou 2013년 3월 15일
or you can try :
a=1:4;
v=perms(a); % ALL possible combinations
Z=[v(:,1:2);v(:,3:4)];% Z is 2 columns
  댓글 수: 2
Cedric
Cedric 2013년 3월 15일
+1
abdulhakeem
abdulhakeem 2013년 3월 15일
Dear Youssef KHMOU,
Thank you very much that is exactly I want. I appreciate That.
Best Regards

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Youssef  Khmou
Youssef Khmou 2013년 3월 15일
편집: Youssef Khmou 2013년 3월 15일
hi,
Random sequence derived from which distribution ?
Z=rand(4); % from Uniform distribution.
Z=randn(4); % from Normal distribution.
Z=random('rayl',(1:4)'*(1:4)) % from Rayleigh distribution

Cedric
Cedric 2013년 3월 15일
편집: Cedric 2013년 3월 15일
A basic approach, but dangerous as you don't know how much time it will take, could be..
ii = randi(4, 4, 1) ;
jj = randi(4, 4, 1) ;
while any(jj == ii)
jj = randi(4, 4, 1) ;
end
Z = [ii, jj]
If you don't want repetitions within ii or jj, you can use RANDPERM.
  댓글 수: 1
abdulhakeem
abdulhakeem 2013년 3월 15일
Thank you I appreciate your help

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by