MATLAB: Combinations of multiplications of a vector

#nchoosekcombinations

Hi, I need to create a combination of multiplications of values of the vector without repetition. For example, I have vector inp = {['f1'] ['f2'] ['f3'] ['f4']},(where f1-4 is a predetermined value), the output should look like this: f1, f2, f3, f4, f1*f2, f1*f3, f1*f4, f2*f3, f2*f4, …. f1*f2*f3*f4. But it should not be displayed in this form, and as the result of the multiplication. I tried to implement it by taking the code from one of the topics on the forum, but it only creates arrays of these combinations. I can not understand how to modify this code to add the multiplication. p.s. Sorry for my English, I communicate through Yandex translator 🙂
if true
inp = {['f1'] ['f2'] ['f3'] ['f4']}
out = cell(size(inp));
for k = 1:numel(inp)
out{k} = num2cell(nchoosek(1:numel(inp),k),2);
end
out = vertcat(out{:})';
Pf = {};
for k = 1:numel(out)
inp(out{k})
b = horzcat(inp{out{k}})
Pf=[Pf [b]];
end
end

Best Answer

inp = 1:4;
out = yourmultnchoosek(inp)
here yourmultnchoosek - function:
function out = yourmultnchoosek(inp)
n = numel(inp);
a = cell(n,1);
for ii = 1:n
a{ii} = prod(nchoosek(inp,ii),2);
end
out = cat(1,a{:});
end