matching digits

2 visualizaciones (últimos 30 días)
joseph Frank
joseph Frank el 30 de Jun. de 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?

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 30 de Jun. de 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)

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by