Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

HOW TO USE RANDOM and Cross paired?

1 Ansicht (letzte 30 Tage)
Kaiser
Kaiser am 21 Mär. 2017
Geschlossen: MATLAB Answer Bot am 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?*

Antworten (2)

Thorsten
Thorsten am 21 Mär. 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 Kommentar
Kaiser
Kaiser am 24 Mär. 2017
I can't understand you. Can you please write the complete answer to me?

Roger Stafford
Roger Stafford am 24 Mär. 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);

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by