V = [ 19 15 11 2 16 3 1 18 14 3 18 19 1 13 16 14 19 15 4 14 3 1 2 16 4 3 1 19 3 20 4 13 1 15 2 18 4 1 19 17 3 1 13 3 4 17 18 19 14 ;
19 16 11 2 16 15 1 18 14 3 18 19 14 2 16 14 19 15 4 14 3 11 2 16 4 3 1 19 3 20 4 13 1 4 2 18 4 1 19 17 3 19 13 3 4 17 18 19 14 ];
A= [0 15 11 2 4 0 3 1 13;
14 0 16 0 0 0 0 0 0;
0 0 0 0 8 0 0 0 0;
0 0 18 0 0 0 0 0 0;
0 0 19 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0];
for i= 1:size(V,1)
VVV = [V(i,:), NaN(1, mod(-size(V,2), 10))];
V10 = reshape(VVV, 10, []);
[~, where] = ismember(V10, A);
[~, col] = ind2sub(size(A), where);
[~, order] = sort(col, 1);
X (i,:) = reshape(V10(order + (0:size(order, 1):numel(order)-1)), 1, []);
B(i,:) = X(~isnan(X(i,:)))';
end