|
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
message news:istr33$hfk$1@newscl01ah.mathworks.com...
> "samira" wrote in message <istqhi$fjr$1@newscl01ah.mathworks.com>...
>> Hi I would like to define a vector of my desired numbers and then ask
>> matlab to generate random numbers only form the number I have in the
>> vector.
>>
>> for example this is my vector [ 0.2, 0.6, 1.2, 0.7]
>>
>> so my results after generating random numbers by matlab should only
>> consist of these 4 values.
>>
>> Thanks for your help
> - - - - - - - -
> v = [ 0.2, 0.6, 1.2, 0.7];
> n = 100;
> x = v(ceil(length(v)*rand(1,n)));
Or if you're using a newer version, you can use RANDI.
v = [0.2 0.6 1.2 0.7];
n = 100;
x = v(randi([1 numel(v)], 1, n));
--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
|