MATLAB: Matching digits

matching

I have 3 vectors A, B, and C that consist of 4 digits each. is it possible to find the common digits at the beginning of each number. for example: A=1234; B=1248, C =1238; the common two digits are 12. how can I do this matching using matlab?

Best Answer

A=1234; B=1248; C =1238;
Astr = num2str(A); %you'll need this one 3x so convert it once.
idxstop = find(any(bsxfun(@ne,vertcat(Astr,num2str(B),num2str(C)),Astr),1),1,'first');
common = Astr(1:idxstop-1)