How to calculate random number between Inf and 10 ?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Suppose i have a matrix given below
A= [-Inf 52.17 54 55.82 Inf]
Now how to calculate a random number between A(1) & A(2) and the random number should be a value, not Inf
Can anyone please help me with this
0 comentarios
Respuestas (1)
Ameer Hamza
el 18 de Oct. de 2020
Editada: Ameer Hamza
el 18 de Oct. de 2020
The most negative value representable in double datatype is given by -realmax. You can do something like this
A= [-Inf 52.17 54 55.82 Inf];
x = rand();
y = x*(-realmax) + A(2);
3 comentarios
Ameer Hamza
el 18 de Oct. de 2020
You can do something like this
A = [-Inf 52.17 54 55.82 Inf];
B = A(:);
B(isinf(B)) = sign(B(isinf(B))).*realmax;
C = rand(numel(B)-1,1).*(B(2:end)-B(1:end-1)) + B(1:end-1);
Ver también
Categorías
Más información sobre Particle & Nuclear Physics 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!