Andrei's version looks plausible, but you will need to decide whether you want .* (element by element multiplication) or if you want bsxfun() (create array with all of the combinations of values), or if you want to transpose one of the vectors and do a matrix multiplication.