How to calculate random number between Inf and 10 ?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Ameer Hamza
2020-10-18
编辑:Ameer Hamza
2020-10-18
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 个评论
Ameer Hamza
2020-10-18
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);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!