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
Just for the sake of completeness:
randVec = 2*randi([0 1], 1,6) - 1;