Vector inputs in functions

4 views (last 30 days)
Matthew Pearson
Matthew Pearson on 18 Sep 2015
Answered: Walter Roberson on 18 Sep 2015
How do I make a function so that it accepts any vector input? I need to create a function that returns a random element of the input vector. I know I need to use rand or randi for it, but I don't know how to input the vector.

Answers (1)

Walter Roberson
Walter Roberson on 18 Sep 2015
function y = randsample(x)
y = x(randi(numel(x));

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!