Is there a quick and easy method of taking some vector [x,y,z] and generating [xx,xy,xz,yy,yz,zz] ?
nchoosek is going to omit the squared terms. I can manually adding them... Just wondering if there's a better solution
Is there a quick and easy method of taking some vector [x,y,z] and generating [xx,xy,xz,yy,yz,zz] ?
nchoosek is going to omit the squared terms. I can manually adding them... Just wondering if there's a better solution
Assuming that the vector consists only of single elements, one way I can suggest is to use a combination of find and triu. Given that your vector is stored in the variable A, try:
[X,Y] = find(triu(ones(numel(A))));
P = A(X).*A(Y);
triu extracts out the upper triangular portion of the matrix. By extracting out the upper triangular portion of a matrix entirely of ones, we can use find to determine the row and column locations of the non-zero entries. Each row and column location corresponds to a pair of locations in your vector that you would multiply together to achieve your desired result. The row and column locations would be stored in X and Y respectively which you would then use to access the vector A and element-wise multiply to achieve the desired result.