MATLAB: How to multiply each row with all rows within a column vector

multiplication within vector elements

I have a vector A=[2; 3; 5; 6] , I would like to multiply each row with all other rows to get a matrix. In this case, the output should be Output=[ 6 6 10 12; 10 15 15 18; 12 18 30 30]. For example, the first column of the output will be obtained by multiplying the first element of A with all the elements to get the Output(:,1)=[A(1,:)*A(2,:),A(1,:)*A(3,:), A(1,:)*A(4,:)]. Similarly, I would want to do for 2nd 3rd and 4th elemnt of A. But as you notice, my way is manual. Is there a rather quicker, more automated, way to obtain the Output as I showed above. Thanks in advance

Best Answer

m=length(A);
B=A*A.';
B(1:m+1:end)=[];
Output=reshape(B,m-1,[])