Q:

Write a function called pickone, which will receive one input argument x, which is a vector, and will return one random element from the vector. For example,

0

 Write a function called pickone, which will receive one input argument x, which is a vector, and will return one random element from the vector. For example,

>> pickone(4:7)

ans =

5

>> disp(pickone(-2:0))

-1

>> help pickone

pickone(x) returns a random element from vector x

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

pickone.m

function elem = pickone(invec)

% pickone(x) returns a random element from vector x

% Format of call: pickone(vector)

% Returns random element from the vector

len = length(invec);

ran = randi([1, len]);

elem = invec(ran);

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now