フィルターのクリア

Compare two matrix row by row and check if at least one row is different, enter the if loop

18 ビュー (過去 30 日間)
Hello
I have a problem, here is a simple version of my question. Imagine I have two matrix, I want to compare each line of matrixs to find if there is similarity. then if all the rows are the same, it is no need to enter the if loop, but if at least one row is different it is needed to enter the if loop.
A=[6,6.5;6,9]
B=[6,6;2,3;8,7;6,9]
% compare A and B row by roow
% if there is similarity not enter the if loop
% if there is at least one line of A is not the same as B enter if
if %compare A and B line by line, if at least one row id different
%%
end
  2 件のコメント
the cyclist
the cyclist 2019 年 11 月 5 日
What you are trying to do is not perfectly clear to me, but I'm confident that the ismember command is what you need.
Zarak kh
Zarak kh 2019 年 11 月 5 日
Thanks for you comment, Yes I accept, I try to make it clear since it is in the middle of code and i try to make it as clear as possible.

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

採用された回答

Guillaume
Guillaume 2019 年 11 月 5 日
if is not a looping statement, it's a branching statement. loops are started by for or while.
Anyway,
if any(ismember(A, B, 'rows')) %if any of the rows of A are in B
%do something
else
%do something else
end

その他の回答 (1 件)

the cyclist
the cyclist 2019 年 11 月 5 日
The expression
all(ismember(A,B,'row'))
will be true if every row of A is represented in B, and false if not.
  1 件のコメント
Zarak kh
Zarak kh 2019 年 11 月 5 日
編集済み: Zarak kh 2019 年 11 月 5 日
Thanks again, I think 'any ' works better than 'all' in my problem.

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by