Info

This question is closed. Reopen it to edit or answer.

HOW TO USE RANDOM and Cross paired?

1 view (last 30 days)
Kaiser
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.
_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?*

Answers (2)

Thorsten
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];
  1 Comment
Kaiser
Kaiser on 24 Mar 2017
I can't understand you. Can you please write the complete answer to me?

Roger Stafford
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);

Tags

Community Treasure Hunt

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

Start Hunting!