Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
-1 から 1 の間で 1 x 6 の行列要素をランダムに選択します。
例えば、[-1 1 -1 1 1 1]
[-1 1 -1 1 1 1]
どうやって選ぶの??
可能な値のベクトルを作成し、randiそのベクトルにランダムなインデックスを生成するために使用します。
randi
Choices = [-1 1]; Index = randi(length(Choices), 1, 6); Choices(Index) ans = 1 1 1 -1 1 -1
完全を期すために:
randVec = 2*randi([0 1], 1,6) - 1;