compare 2 vectors and classify them

조회 수: 2 (최근 30일)
Francisco Anaya
Francisco Anaya 2019년 4월 3일
댓글: madhan ravi 2019년 4월 3일
I have an array of 90872x2 double. As follows:
A= B=
1 2
1 2
1 2
1 1
1 1
1 1
1 1
2 1
2 1
2 1
2 1
1 2
1 2
1 2
1 2
1 1
1 1
1 1
2 2
2 2
I want to create a column C with the following values accordinf to the following conditions:
1= when A==1 and B==1;
2= when A==1 and B==2;
3= when A==2 and B==1;
4= when A==2 and B==2;
Therefore I will have:
A= B= C=
1 2 2
1 2 2
1 2 2
1 1 1
1 1 1
1 1 1
1 1 1
2 1 3
2 1 3
2 1 3
2 1 3
1 2 2
1 2 2
1 2 2
1 2 2
1 1 1
1 1 1
1 1 1
2 2 4
2 2 4
any help?
  댓글 수: 3
Francisco Anaya
Francisco Anaya 2019년 4월 3일
편집: Francisco Anaya 2019년 4월 3일
Im sorry you are right, the conditions are:
1= when A==1 and B==1;
2= when A==1 and B==2;
3= when A==2 and B==1;
4= when A==2 and B==2;
Therefore I need:
A= B= C=
1 2 2
1 2 2
1 2 2
1 1 1
1 1 1
1 1 1
1 1 1
2 1 3
2 1 3
2 1 3
2 1 3
1 2 2
1 2 2
1 2 2
1 2 2
1 1 1
1 1 1
1 1 1
2 2 4
2 2 4
I CORRECTED the ortiginal questions. Can you please help me?
madhan ravi
madhan ravi 2019년 4월 3일
Sure see my answer below.

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

채택된 답변

madhan ravi
madhan ravi 2019년 4월 3일
편집: madhan ravi 2019년 4월 3일
C = 1 * (A==1 & B==1) + 2 * (A==1 & B==2) +...
3 * (A==2 & B==1) + 4 * (A==2 & B==2)

추가 답변 (1개)

KSSV
KSSV 2019년 4월 3일
C = A ;
C(A ==1 & B == 1) = 1 ;
C(A ==1 & B == 2) = 2 ;
C(A ==2 & B == 1) = 3 ;
C(A ==2 & B == 2) = 4 ;

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by