0

Let say we have 2 vectors of A and B,

A=[1;2;5;6;7;9]; B=[1;3;4;7];

How to find value C that are available in both A and B? The expected value should be C=[1;7]

Acobot
  • 27
  • 6

2 Answers2

1

Since the title of your question says "similar", I assume you want to compare with a given tolerance. For that you can use ismembertol:

tol = 1e-3;
A = [1; 2 ; 5 ; 6 ; 7 ; 9];
B = [1.0001; 3.0001; 4.0001; 7.0001];
ind = ismembertol(A, B, tol);
C = A(ind);
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
0

Very simple:

A=[1;2;5;6;7;9]; 
B=[1;3;4;7];
C=intersect(A,B)
Mendi Barel
  • 3,350
  • 1
  • 23
  • 24