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.
Asked
Active
Viewed 9,102 times
1
-
Use [WHICH](http://www.mathworks.com/help/techdoc/ref/which.html) to check for the existence of the RANDI function first so that you don't overload it for users running modern MATLAB versions. – b3. Aug 18 '11 at 20:22
-
@b3: I would use EXIST instead of WHICH: `exist('randi','builtin')==5` – Amro Aug 18 '11 at 20:54
-
BTW, this post answers your question: http://stackoverflow.com/questions/6415424/using-rand-in-matlab-to-produce-numbers-between-limits/6415698#6415698 – Amro Aug 18 '11 at 20:56
1 Answers
3
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
-
1To be exact, `randi([m,n])` means generate a number in the interval [m,n], which is not the same as `rand([m,n])` which generates a matrix of size m-by-n of uniform numbers – Amro Aug 18 '11 at 20:54