Random numbers

1 次查看(过去 30 天)
Sujan
Sujan 2012-4-18
I have a problem regarding random numbers. Suppose I have a zero vector with length 10. I want to generate random numbers only on position 1,2,4,7,8. How do I generate random numbers only on these positions ? Is there any command ?

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-4-18
idx = [1,2,4,7,8];
out = zeros(10,1);
out(idx)=rand(numel(idx),1);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by