how could I use the "find" command to compare two matrices?

Hello Matlabers,
I have 2 matrices (with 1 column and 2000 rows each) and I would like to compare each row from each matrix and get a 3rd logical matrix with 1's or 0's depending on the case... so far I tried to use the command:
control_matrix=find(A)<(B);
and this is supposed to generate a control matrix with 1's and 0's with the same size (1 column and 2000 rows) but when I apply the command it does not give me back the correct results...
any idea, suggestion or hint?
thanks! :)

 採用された回答

Laura Proctor
Laura Proctor 2012 年 12 月 18 日
編集済み: Laura Proctor 2012 年 12 月 18 日

1 投票

Comparing two matrices directly will give back a logical array:
control_matrix= A<B;
The find function will find the index values where items are nonzero.

3 件のコメント

Elsis
Elsis 2012 年 12 月 18 日
thanks but this is not what I want to do... doing this returns a matrix with a different size... yes, it solves the logic but not gives a matrix with the proper size (2000 rows) it only tells me the index values and in my case this is a matrix with only 895 rows... what I want is a logical matrix with 1's and 0's depending if the condition is fulfilled o not (per row) with the size of 1 column and 2000 rows...
any other idea???
Laura Proctor
Laura Proctor 2012 年 12 月 18 日
Did you try this command? It doesn't use find. If A & B are both 1x2000 element arrays, then it will return a 1x2000 element logical array containing 1's and 0's. The use of find returns the index values. Try it!
Image Analyst
Image Analyst 2012 年 12 月 18 日
Obviously Elsis, you did NOT try the code she provided. I think you just ran your original code instead.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および 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