"Roger Stafford" wrote in message <isivhv$7hq$1@newscl01ah.mathworks.com>...
> "Cliff" wrote in message <isiod2$dmo$1@newscl01ah.mathworks.com>...
> > This should be a simple problem but I haven't been able to figure out an efficient way to do it. If I have a matrix, or vector, and I want to multiply each element by every other element, and every combination of multiples of every other element, what is the best way to do it?
> >
> > for ex: [1 2 3 4 5] would go to
> >
> > [1, 2, 3, 4, 5, 2*3, 2*4, 2*5, 2*3*4, 2*4*5, 3*4*5, 4*5, 3*5, 3*4, 2*3*4*5]
> > .........
>           
> Let v be a row vector.
>
> n = size(v,2);
> p = ones(2^n,1);
> m = 1;
> for k = 1:n
> t = prod(nchoosek(v,k),2);
> p(m+1:m+length(t)) = t;
> m = m + length(t);
> end
>
> This should get all possible products of v elements in vector p.
>
> Roger Stafford
       
Or here is a vectorized method. Again let v be a row vector.
n = size(v,2);
t = dec2bin(0:2^n1,n)'0';
p = prod(bsxfun(@times,v,t)t+1,2);
Roger Stafford
