In the general case, when you have Ndifferent lines, and each of these lines occurs a different number of times M_i, then each corresponding set of values Bwill have a different length, and you will not be able to combine the sets together into a number array. Instead, you have to store the sets in the N-element array , and you can do this using the UNIQUE and ACCUMARRAY functions :
>> A = {'a' 'b' 'b' 'c' 'a' 'a' 'a' 'c' 'd' 'b'}; %
>> B = 1:10; %
>> [uniqueStrings,~,index] = unique(A)
>> associatedValues = accumarray(index(:),B,[],@(x) {x})
associatedValues =
[4x1 double] %
[3x1 double] %
[2x1 double] %
[ 9] %
, , , :
associatedValues = [associatedValues{:}];
: ACCUMARRAY , , associatedValues , B. B ACCUMARRAY :
associatedValues = accumarray(index(:),1:numel(B),[],@(x) {B(sort(x))});
ACCUMARRAY, :
[index,sortIndex] = sort(index);
associatedValues = accumarray(index(:),B(sortIndex),[],@(x) {x});