## Combination of 4 Element

### Machmud Roby Alhamidi (view profile)

on 21 Oct 2019
Latest activity Edited by Andrei Bobrov

on 22 Oct 2019

### Jos (10584) (view profile)

How do i put this to the simple way?
bl is a cell contained one or two elements
a1 = cell2mat(bl(1));
a2 = cell2mat(bl(2));
a3 = cell2mat([bl(1) bl(2)]);
a4 = cell2mat(bl(3));
a5 = cell2mat([bl(1) bl(3)]);
a6 = cell2mat([bl(2) bl(3)]);
a7 = cell2mat([bl(1) bl(2) bl(3)]);
a8 = cell2mat(bl(4));
a9 = cell2mat([bl(1) bl(4)]);
a10 = cell2mat([bl(2) bl(4)]);
a11 = cell2mat([bl(1) bl(2) bl(4)]);
a12 = cell2mat([bl(3) bl(4)]);
a13 = cell2mat([bl(1) bl(3) bl(4)]);
a14 = cell2mat([bl(2) bl(3) bl(4)]);
a15 = cell2mat([bl(1) bl(2) bl(3) bl(4)]);
i tried using
for i=1:4
a{i}=combnk(bl,i);
end
but end up with cell in cell element, and it is hard to access.
thank you.

### Jos (10584) (view profile)

on 21 Oct 2019

I make use of my function NCHOOSE, available here:
% bl is a cell array with four elements, each cell has 1 or 2 elements.
bl = {1 , [2 3], 4, [5 6]}
bi = nchoose(1:numel(bl))
a = cellfun(@(k) [bl{k}], bi, 'un', 0 )

#### 1 Comment

Machmud Roby Alhamidi

### Machmud Roby Alhamidi (view profile)

on 22 Oct 2019
wow, this is works
thank you

### Andrei Bobrov (view profile)

on 21 Oct 2019
Edited by Andrei Bobrov

### Andrei Bobrov (view profile)

on 22 Oct 2019

bl = cellfun(@(x)x(:)',bl,'un',0);
n = numel(bl);
ii = cell(n,1);
for i = 1:n
ii{i} = num2cell(nchoosek(1:4,i),2);
end
a = cellfun(@(x)[bl{x}],cat(1,ii{:}),'un',0);

Machmud Roby Alhamidi

### Machmud Roby Alhamidi (view profile)

on 21 Oct 2019
i found this error if i change iii to ii
"Function 'subsindex' is not defined for values of class 'cell'."
Andrei Bobrov

### Andrei Bobrov (view profile)

on 21 Oct 2019
I'm fix.
Machmud Roby Alhamidi

### Machmud Roby Alhamidi (view profile)

on 22 Oct 2019
Thank you Andrei Bobrov