Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
HOW TO USE RANDOM and Cross paired?
조회 수: 1 (최근 30일)
이전 댓글 표시
there are two conditions
(1) K1 + K2 + K3 =1
(2) K1 > K2 > K3
I need 100 random combinations of the K1, K2 and K3
0<Ki's<1, all Ki's must satisfy both the conditions
the question above, I already got the answer. But if anyone has others idea, please comment below.
_The old answer:
N = 100 ;
k = linspace(0,1,N) ;
[K1,K2,K3] = ndgrid(k,k,k) ;
thesum = K1+K2+K3 ;
idx = thesum==1 ;
K1 = K1(idx) ; K2 = K2(idx) ; K3 = K3(idx) ;
K = [K1 K2 K3] ;
idx = K1<K2 & K2<K3 ;
iwant = K(idx,:) ;_
*Now, here is the new question:
If I want to declare K1 = 0.5? how to generate K2 and K3?*
댓글 수: 0
답변 (2개)
Roger Stafford
2017년 3월 24일
Use my randfixedsum in the File Exchange at:
http://www.mathworks.com/matlabcentral/fileexchange/9700-random-vectors-with-fixed-sum
K = sort(randfixedsum(3,100,1,0,1),1,’descend’);
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!