Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

HOW TO USE RANDOM and Cross paired?

1 visualizzazione (ultimi 30 giorni)
Kaiser
Kaiser il 21 Mar 2017
Chiuso: MATLAB Answer Bot il 20 Ago 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?*

Risposte (2)

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

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

Questa domanda è chiusa.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by