Assigning New Matrix Elements Based On Comparing 2 Matrices

조회 수: 1 (최근 30일)
Kiran
Kiran 2014년 2월 16일
답변: Kiran 2014년 2월 16일
Say I have 2 Matrices of equal dimensions, say A and B. I need to compare them element by element. If the element in A is greater than the like for like element in B, assign a '1' for that like for like element in C. For when the like for like elements in A and B are equal, assign the value '2' in C. I have played around with the max function and a few inequalities but to no avail. Any help will be greatly appreciated.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 2월 16일
편집: Andrei Bobrov 2014년 2월 16일
C = (A >= B) + (A == B);

추가 답변 (1개)

Kiran
Kiran 2014년 2월 16일
Both answers are spot on. Thank you very much for your help.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by