comparing the two column in MATLAB

Hello!
Let, A=[ 1 2 ; 2 2; 3 4; 4 4]
I want to compare the 1st column with the 2nd column to find out if there is any row having the same values in both columns.
Say, in the example, 2nd and 4th rows have the same values in both the two columns. i need to find the rows where the condition is satisfied.
Could you please help me?

 採用された回答

madhan ravi
madhan ravi 2018 年 11 月 22 日
編集済み: madhan ravi 2018 年 11 月 22 日

2 投票

rowswithidenticalvalues=find(A(:,1)==A(:,2)) %1 indicates the values are the same

5 件のコメント

Sky Scrapper
Sky Scrapper 2018 年 11 月 22 日
編集済み: Sky Scrapper 2018 年 11 月 22 日
That's working. Thanks.
another question:
I want to check if , value of column 1= - ( value of column 2)
as for example, A[ 1 2; 10 -10],
then how to write the code to compare the two columns?
madhan ravi
madhan ravi 2018 年 11 月 22 日
A(:,1) == - A(:,2)% just put minus infront that’s it
Sky Scrapper
Sky Scrapper 2018 年 11 月 22 日
Thanks!
madhan ravi
madhan ravi 2018 年 11 月 22 日
Anytime :)
Celestie Gladys
Celestie Gladys 2023 年 1 月 26 日
@madhan ravi if i have to find the same colums in not just for 1st and 2nd colum but for the entire matrix ?

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by