MATLAB: Q matrices element matching

matrix array

i have a matrix like
A=[1 2 3 4 5;
1 2 3 4 6
1 3 4 5 8];
i want a output like X=[1 2 3 4 0]
i.e. i need the common element in the particular coloumn if there is no particular coloum result must b zero

Best Answer

X = zeros(1, size(A,2));
mask = A(1,:) == A(2,:) | A(1,:) == A(3,:);
X(mask) = A(1,mask);
mask = A(2,:) == A(3,:);
X(mask) = A(2,mask);
Related Question