フィルターのクリア

An expression for choosing a value from the array automatically

2 ビュー (過去 30 日間)
Priya
Priya 2014 年 5 月 19 日
コメント済み: Priya 2014 年 5 月 19 日
Hi,
I have an array of values and I need to frame an expression such that it chooses the value from the array automatically instead of me assigning a value from the array everytime. For example, if
A=[1 2 3 4]
B=[5 6 7 8]
while initialising A, B for the first time I choose A=2, and B=6 (A and B are selected with corresponding element) and next time A=4, B=8
Could someone please give some suggestions.

採用された回答

Yohai
Yohai 2014 年 5 月 19 日
The function
choose=@(arr) arr(ceil(rand*length(arr)))
chooses a random element of a vector. For example
choose([1 2 pi 8 i])
3.1416
  2 件のコメント
Priya
Priya 2014 年 5 月 19 日
Thanks for your reply. Could you please replace with A and B in the equation you have mentioned. I don't get it completely.
Priya
Priya 2014 年 5 月 19 日
Thanks very much. It worked!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by