Vector inputs in functions

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.

Respuestas (1)

Walter Roberson
Walter Roberson el 18 de Sept. de 2015

0 votos

function y = randsample(x)
y = x(randi(numel(x));

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 18 de Sept. de 2015

Respondida:

el 18 de Sept. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by