How does the "find" command work with arrays?

2 ビュー (過去 30 日間)
M2ohamad
M2ohamad 2015 年 2 月 4 日
編集済み: John D'Errico 2015 年 2 月 5 日
So here's my code:
A1 = [1 2; 3 4];
A2 = [0 1; 5 6];
GlobalProd = A1*A2;
IndividProd = A1.*A2;
M1 = find(IndividProd)
M2 = find(GlobalProd)
Here's the output:
M1 =
2
3
4
M2 =
1
2
3
4
I am wondering what values the find command was looking for, since I put the name of an array instead of a specific value?
Thank you.

採用された回答

John D'Errico
John D'Errico 2015 年 2 月 4 日
編集済み: John D'Errico 2015 年 2 月 5 日
Find looks for NON-zero values. It returns the index of those elements, as they are stored in memory. Remember that elements are stored down columns, so all elements of the first column are first, then the second column.
A linear index is the index of what you would get if you unrolled the array into a long column vector.
If you give find a second return argument, then it returns row and column indices for the non-zeros.
By the way, this is stated in the help, so you could have learned this as easily and more rapidly, simply by reading the help for find. A good way to learn these things is by reading the help, then try some test cases of your own.

その他の回答 (0 件)

カテゴリ

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