You can use simple old matrix operations, for example. at
x = [3,2,1]; y = [11,22,33,44,55]; v = [(ones(length(y),1) * x)(:), (ones(length(x), 1) * y)'(:)]
Edit: this is Octave syntax, MATLAB will look like this:
x = [3,2,1]; y = [11,22,33,44,55]; A = ones(length(y),1) * x; B = (ones(length(x), 1) * y)'; v = [A(:) B(:)]
in both cases the result will be
v = 3 11 3 22 3 33 3 44 3 55 2 11 2 22 2 33 2 44 2 55 1 11 1 22 1 33 1 44 1 55
jihor May 23 '17 at 20:59 2017-05-23 20:59
source share