Create a random vector only with positive numbers
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Marta
el 2 de Sept. de 2022
Comentada: Marta
el 2 de Sept. de 2022
Hello, I'm new in matlab and I want to create a vector only with positive numbers.
I usually use the function "randn()" but i can't control the sign of the element.
Thank you! :)
0 comentarios
Respuesta aceptada
Matt J
el 2 de Sept. de 2022
Editada: Matt J
el 2 de Sept. de 2022
If you don't care what the distribution is, infinite possible recommendations can be made. You can use a classically non-negative distribution, e.g., rand, poissrnd, randi,...
Or, you can improvise and do things like,
x=randn(1,5).^2
or
x=abs(randn(1,5))
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!