MATLAB: How to determine number of common elements between two vectors elementsamevector for example X = 1:10 Y = [5,7,13,25,45,56] So 5 and 7 are the common elements, and the answer should be 2. Best Answer numel( intersect( X, Y ) ) Related SolutionsMATLAB: Vector Difference y = [x(1) diff(x)] MATLAB: Common numbers between arrays You could write some code using the intersect( ) function for this. E.g., the first result>> A = {[1,2,3], [3 4 5 6], [3 7 8 2], [11 3 15]}A = 1×4 cell array {1×3 double} {1×4 double} {1×4 double} {1×3 double}>> intersect(A{1},[A{2:4}])ans = 2 3You could write a loop where each cell is compared to a merging of the other cells as shown above. Related QuestionFind missing elements of a vectorFind distance between row vectorsFind a common element between two matrices of different sizesCombine 2 vectors to one result vectorFind the common number in rows
Best Answer