As per my comment to your question: numbered variables are always an indication that your design is wrong. You should never have variables a_1, a_2, ... Instead you should have just one a variable (a cell array, a matrix, whatever is appropriate) that you index, e.g. a(1), a(2), ... With that design the ndgrid assignment is trivial.
x = [0 1]'; y = [1 0]';
m = 10; n = 7;
c = repelem({x, y}, [m, n]);
[c{:}] = ndgrid(c{:});
c = reshape(cat(m+n+1, c{:}), [], m+n);
a = c(:, 1:m);
b = c(:, m+1:end);
a(:, i) is your a_i, b(:, i) is your b_i.
Best Answer