MATLAB: About Preallocating for speed

preallocation

What is a more efficient way of writing this code?
NumberedOD = [];
for a = 1:(N-1)
for b = (a+1) :N
NumberedOD = [NumberedOD;a, b];
end
end
My aim is to get a list of numbers like this:
1 2
1 3
.
.
1 N
2 3
2 4
.
.

Best Answer

NumberedOD = nchoosek(1:N, 2);