Borrar filtros
Borrar filtros

Can Matlab give me a disturbance randomly from a% to b% of a number?

2 visualizaciones (últimos 30 días)
Ben Le
Ben Le el 18 de Feb. de 2017
Editada: Ben Le el 18 de Feb. de 2017
Hello everyone,
Let say my number is 7, and I need to generate a randomly number from 5 to 400% of 7. Can Matlab give me the randomly numbers? Thank you in advance for your help!
Ben

Respuesta aceptada

Matt J
Matt J el 18 de Feb. de 2017
Editada: Matt J el 18 de Feb. de 2017
ub=4*7; %upper bound
lb=.05*7; %lower bound
num=(ub-lb)*rand+lb
  2 comentarios
John D'Errico
John D'Errico el 18 de Feb. de 2017
Hmm. I interpret the lower limit differently from the question. You may be right though.
Ben Le
Ben Le el 18 de Feb. de 2017
Thank you very much, Matt!

Iniciar sesión para comentar.

Más respuestas (1)

John D'Errico
John D'Errico el 18 de Feb. de 2017
Do you know how to generate uniform random numbers in an interval [x,y]? This is in the help for rand, so you should know, or be able to find out.
doc rand
Here, your limits are
[5,4*7]
since 4*7 is 400% of 7. Just read the help.
  1 comentario
Ben Le
Ben Le el 18 de Feb. de 2017
Editada: Ben Le el 18 de Feb. de 2017
John, Thanks for your suggestion. The doc rand doesn't help because it gives me a vector or a matrix. I need a single value to avoid conflicting with dimensions of other parameters in the function. Thanks again for the suggestion!

Iniciar sesión para comentar.

Categorías

Más información sobre Logical 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