Reputation: 10199
The following code supposed to output the content of 1st cell in combs and access to each row of the cell which is defined by bb. My issue here is that it doesn't loop over to 2nd and 3rd cell.
% input arrays
A=[2 1 3];
B=[4 2 1 3 3];
C=[1 3];
D=[3 2 4 2 1 1];
E=[4 1 1];
% possible subsets of a set
combs = arrayfun(@(x) nchoosek({A,B,C,D,E},x),3:numel({A,B,C,D,E}),'Uniform',0);
for j=1:numel(combs)
aa=combs{j}
for g=1:numel(aa)
bb=aa(g,:)
end
end
It only loop for the first cell array then this error message occur:
Index exceeds matrix dimensions.
Error in simtt1 (line 18) bb=aa(g,:)
May I know how to make it loop for 2nd cell and 3rd cell?
Upvotes: 0
Views: 86
Reputation: 221514
Since that iterator g
is used to index into the rows of aa
, you need to iterate it from 1 to size(aa,1)
. Thus, make this edit in your code -
for g=1:size(aa,1)
It worked for the outer loop iterator - for j=1:numel(combs)
, because combs
is a 1D
cell array.
Upvotes: 1