Vector inputs in functions

4 ビュー (過去 30 日間)
Matthew Pearson
Matthew Pearson 2015 年 9 月 18 日
回答済み: Walter Roberson 2015 年 9 月 18 日
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 日
function y = randsample(x)
y = x(randi(numel(x));

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by