compare 2 vectors and classify them
Show older comments
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 Comments
madhan ravi
on 3 Apr 2019
1= when A==1 and B==1;----
2= when A==1 and B==2; |---- are the same???
3= when A==1 and B==1;----
4= when A==2 and B==1;
Francisco Anaya
on 3 Apr 2019
Edited: Francisco Anaya
on 3 Apr 2019
madhan ravi
on 3 Apr 2019
Sure see my answer below.
Accepted Answer
More Answers (1)
KSSV
on 3 Apr 2019
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 ;
Categories
Find more on Classification in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!