Borrar filtros
Borrar filtros

Random numbers

1 visualización (últimos 30 días)
Sujan
Sujan el 18 de Abr. de 2012
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 ?

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by