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.
我只需要在 Octave 中生成一个 1xn 的预定数字向量。我必须生成一个 0.7 和 1.8 的 1xn 随机序列。我该怎么做?
我将其视为“0.7 和 1.8 的随机序列”,您的意思是每个条目都是 0.7 或 1.8,每个条目的概率为 0.5
为此,您可以这样做:
r = rand(1,n); v = zeros(1,n); v(r < 0.5) = 0.7; v(r >= 0.5) = 1.8;