HOW TO USE RANDOM?

2 次查看(过去 30 天)
Kaiser
Kaiser 2017-3-1
编辑: Kaiser 2017-3-1
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 个评论
Kaiser
Kaiser 2017-3-1
Thank you very much!
KSSV
KSSV 2017-3-1
You have to accept the answer, if it is useful to you. That is thanking in mathworks.

请先登录,再进行评论。

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by