matching digits

8 views (last 30 days)
joseph Frank
joseph Frank on 30 Jun 2011
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?

Accepted Answer

Sean de Wolski
Sean de Wolski on 30 Jun 2011
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)

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!