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.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 9월 18일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2015년 9월 18일

답변:

2015년 9월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by