Clear Filters
Clear Filters

HOW TO USE RANDOM?

3 views (last 30 days)
Kaiser
Kaiser on 1 Mar 2017
Edited: Kaiser on 1 Mar 2017
there are two formulas
K1 + K2 + K3 =1 (1)
K1 > K2 > K3 (2)
I need 100 random combinations of the K1, K2 and K3
how can I do in the MATLAB
  9 Comments
Kaiser
Kaiser on 1 Mar 2017
Thank you very much!
KSSV
KSSV on 1 Mar 2017
You have to accept the answer, if it is useful to you. That is thanking in mathworks.

Sign in to comment.

Accepted Answer

KSSV
KSSV on 1 Mar 2017
Edited: KSSV on 1 Mar 2017
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,:) ;
  3 Comments
KSSV
KSSV on 1 Mar 2017
idx gives the indices of the elements in the array/ matrices satisfying given condition.
Kaiser
Kaiser on 1 Mar 2017
Edited: Kaiser on 1 Mar 2017
Okay, I see~!
second~
If I want to declare K1 = 0.5? Can I only change the "K1=K1(idx)" to "K1=0.5" ?

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!