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 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