Info

# HOW TO USE RANDOM and Cross paired?

1 view (last 30 days)
Kaiser on 21 Mar 2017
Closed: MATLAB Answer Bot on 20 Aug 2021
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.
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?*

Thorsten on 21 Mar 2017
K2 = 0.5*rand(100, 1);
K2(K2 < 0.25) = 0.25 + K2(K2 < 0.25);
iwant = [0.5*ones(100, 1), K2, 0.5 - K2];
Kaiser on 24 Mar 2017
I can't understand you. Can you please write the complete answer to me?

Roger Stafford on 24 Mar 2017
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);