在MATLAB中使用'rand'实现'randi' [英] Implement 'randi' using 'rand' in MATLAB
本文介绍了在MATLAB中使用'rand'实现'randi'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为了增加向后兼容性,我想将所有"randi([m,n])"替换为仅使用rand的某个函数,因为使用较早版本的MATLAB的人没有randi函数.
To increase backward compatibility i want to replace all my "randi([m,n])" to some function that uses only rand, as people with earlier versions of MATLAB do not have randi function.
推荐答案
如果您在谈论randi(imax,[m,n])
,则可以使用类似以下内容的东西:
If you're talking about randi(imax,[m,n])
, you could use something like:
ceil(imax*rand([m,n]))
如果您的意思是randi([imin,imax])
,请参阅注释中提供的Amro链接:
If you mean randi([imin,imax])
, refer to the link Amro provided in the comments: Using rand in matlab to produce numbers between limits
这篇关于在MATLAB中使用'rand'实现'randi'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文