matching digits

7 次查看(过去 30 天)
joseph Frank
joseph Frank 2011-6-30
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?

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by