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

35 views (last 30 days)
Zarak kh
Zarak kh on 5 Nov 2019
Edited: Zarak kh on 5 Nov 2019
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.
% 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
Zarak kh
Zarak kh on 5 Nov 2019
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.

Sign in to comment.

Accepted Answer

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

More Answers (1)

Community Treasure Hunt

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

Start Hunting!