A = ['a' 'a' 'b' 'c' 'c' 'd' 'd' 'd' 'd' 'e' 'e']
B = ['d' 'a' 'c' 'b' 'e']
sizeA = length(A)
sizeB = length(B)
You can use the container.Map to track the frequency of the characters. This approach will also work when A is not sorted.
M = containers.Map
M(A(i)) = M(A(i)) + 1;
M(A(i)) = 1;
You will get the map M, which contains the characters as a key and frequency as their value.
Now using following code you can get the desired output.
str = "";
str = strcat(str,B(i));