I would like to find out if there is a function that can generate random numbers from a set of numbers in Matlab? For instance say I have the set [-1 1]. How can I generate numbers from that set? I have tried to use randi([-1,1]) but that obviously will generate the numbers -1,0 and 1 and I would like to generate numbers uniformly WITHOUT the 0 and only include -1 and 1. I apologise in advance if this seems like a trivial question but I can’t seem to find the answer.
Thanks for any help you can provide.
Edit: I’ve found a simple solution for the above: (randi([0 1])*2) – 1. This only solves this problem and not a generation of numbers from a specified set.
Well, is there a function that can generate integers uniformly from the set 1:2, or, in general, from the set 1:n, where n is the number of elements in your set? (Yes)
If the above answer was yes, then can those numbers be used as an index into the generated set? (Yes)
Will it sample randomly and uniformly? (Yes)