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.
我需要创建一个随机标量的 Nx1 列向量,其中向量中所有标量的总和等于 1。向量中的每个标量都需要大于 0 且小于或等于 1。向量可以是可变长度。
生成N随机值。计算它们的总和。将所有值除以总和。
N
function result = randvec(n) num = rand(n,1); result = num / sum(num); end