フィルターのクリア

What is the function of find()

1 回表示 (過去 30 日間)
feit feit
feit feit 2020 年 12 月 1 日
コメント済み: feit feit 2020 年 12 月 1 日
Can anyone help me understanding the below code?
n_actions = find(reward(cs,:)>0);
Where 'reward' is a matrix. For example,
reward = [1 2 3; 3 4 5; 5 6 7]; cs = 1;
Thank you

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 1 日
編集済み: Ameer Hamza 2020 年 12 月 1 日
reward = [1 2 3; 3 4 5; 5 6 7]; cs = 1;
Check the output of your code one part at a time
>> reward(cs,:)
ans =
1 2 3
The above line output cs=1 row of matrix reward. Next we use compairson operator
>> reward(cs,:)>0
ans =
1×3 logical array
1 1 1
This line find which elements are greater than 0. As you can see, all of them are above zero so we get [1 1 1]. Next
>> find(reward(cs,:)>0)
ans =
1 2 3
The find() function return the index of all elements that are non-zero.
For example,
>> find([1 2 0 1 0])
ans =
1 2 4
It shows that element number 1, 2, and 4 are non-zero.
  3 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 12 月 1 日
Thanks Image Analyst :)
feit feit
feit feit 2020 年 12 月 1 日
Many thanks, Hamza!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by