Implement 'randi' using 'rand' in MATLAB
To increase backward compatibility i want to replace all my "randi([m,n])" to some function that uses only rand, as people with e开发者_运维知识库arlier versions of MATLAB do not have randi function.
If you're talking about randi(imax,[m,n])
, you could use something like:
ceil(imax*rand([m,n]))
If you mean randi([imin,imax])
, refer to the link Amro provided in the comments: Using rand in matlab to produce numbers between limits
精彩评论