필터 지우기
필터 지우기

How to compare two matrix?

조회 수: 2 (최근 30일)
Md Jahid Hasan Sagor
Md Jahid Hasan Sagor 2023년 4월 26일
댓글: Md Jahid Hasan Sagor 2023년 4월 27일
Suppose,
A=[4 5;4 19;5 7;4 5];
B=[4 5]
if B in A
calculation1;
end
else
calculation2;
end
How Can I code this?

채택된 답변

DGM
DGM 2023년 4월 26일
편집: DGM 2023년 4월 26일
It's not exactly clear what the intended logic is, but this is a simple membership test
A=[4 5; 4 19; 5 7; 4 5];
B=[4 5];
if ismember(B,A,'rows')
% calculation 1;
disp('B is a member of A')
else
% calculation 2;
disp('B is NOT a member of A')
end
B is a member of A
  댓글 수: 1
Md Jahid Hasan Sagor
Md Jahid Hasan Sagor 2023년 4월 27일
Thank you so much for your help. It works.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Juan Ruiz Osorio
Juan Ruiz Osorio 2023년 4월 26일
편집: Juan Ruiz Osorio 2023년 4월 26일
I think this works if you want to do a calculation for each member of B.
A=[4 5;4 19;5 7;4 5];
B=[4 5];
for i=1:size(B,2)
if ismember(B(i),A)
calculation1;
else
calculation2;
end
end

카테고리

Help CenterFile Exchange에서 Dynamic System Models에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by