How does the "find" command work with arrays?

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by