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,
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:3| Question number:32.3
All Answers
total answers (1)
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