strfind should be an option, especially if you only have positive integer scalars, which you can just cast to char. Otherwise, the solution below might also be an option. It might not scale really well to huge vectors due to that convolution, but that is done on a binary matrix, so that should be as fast as it can be.
Another note: this uses implicit expansion, so if you don't have R2016b or newer, you'll have to use bsxfun.
a=[1 2];b1=[1 3 2 9 5];b2=[1 2 2 9 5];