randi function halt my program from execution sometimes...
15 views (last 30 days)
Show older comments
Hello, does anyone had this kind of problem described in title with randi function.
ps. i also get the same issue with randsample (maybe i ve got a programming issue and both work fine?)
Appreciated !!!
1 Comment
John D'Errico
on 15 Nov 2016
Edited: John D'Errico
on 15 Nov 2016
How can we know what you are doing wrong? The crystal ball is so foggy these days. Maybe I need a new one, or perhaps I can order some crystal ball cleaner online.
Those tools work with no problems for everyone else. So if it causes a problem for you, then you need to post an example that causes a problem. Show the values of the inputs you passed in. How else can we possibly know what you have done wrong?
Would you call your doctor and tell them only that there is a problem with your foot, but give them no more hint at all? Then would you seriously expect them to diagnose your problem over the telephone with only that input? Would you call your mechanic and tell them only that on some days, your car does not run, then expect good advice based on only that input?
Answers (3)
Image Analyst
on 15 Nov 2016
The documentation says:
X = randi(imax,n) returns an n-by-n matrix of pseudorandom integers drawn from the discrete uniform distribution on the interval [1,imax].
Are you perhaps doing that and passing in a large value of n? This will create a 2-D matrix. If n is very large, like a million, then that could take a long time. Perhaps you wanted a 1-D vector of n elements. If that is the case, do this:
r = randi(imax, n, 1); % Column vector
or
r = randi(imax, 1, n); % Row vector
0 Comments
Jan
on 15 Nov 2016
Both work fine. To check, if you have a programming issue, post your code. A frequent mistake is using a larg single input only:
a = randi([0,1], 1e6)
This returns a 1e6x1e6 matrix, which exhausts the memory and let Matlab look like it is frozen. Usually randi([0,1], 1, 1e6) is meant.
0 Comments
stelios krasadakis
on 15 Nov 2016
6 Comments
Image Analyst
on 15 Nov 2016
Are you sure you're not piling stuff up in an axes, like tons of images. This may slow it down quite a bit. You might want to call
cla reset;
before you display anything.
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!