Avoid scripts but use functions. This can increase the speed substantially, but most of all the clarity and maintanability of the code is improved massively.
for i2=1:length(Hcombos(:,1))
This creates a temporary vector only to count the number of elements. Faster:
for i2 = 1:size(Hcombos, 1)
These IF-blocks are a waste of time:
if k22==j
Vehicle2{j,k22}=BEV(:, j);
VID2{j,k22}=ID(j);
else
Vehicle2{j,k22}=BEV(:,k22);
VID2{j,k22}=[ID(k22)];
end
In both cases exactly the same is performed, so omit the IF command and run:
Vehicle2{j, k22} = BEV(:,k22);
VID2{j, k22} = ID(k22);
Do not use cell2mat for a scalar cell element, because the direct indexing with the curly braces is faster:
ID2=cell2mat(VID2(jj2));
% Nicer and faster:
ID2 = VID2{jj2};
The iterative growing of array wastes a lot of resources. Do not define the initial arrays as empty cells, but use the final size fir a pre-allocation.
Do your self and the readers the favor to apply a proper indentation: ctrl-a ctrl-i. The less confusing the indentation is, the easier is the code to read.