MATLAB: Repeat values in a vector

interpolationMATLABvector

Assume
a1=[1 5 8];
b1=[6 4 5];
a2=[1 2 3 4 5 6 7 8];
Now I want to create a matching vector with values repeated as follows:
b2=[6 6 6 6 4 4 4 5];
Thanks in advance!

Best Answer

b2 = b1(cumsum(ismember(a2,a1)));
Related Question