Consider a MATLAB cell U
of size L x 1
, where each sub-cell is a G x K
matrix reporting some numbers. I want to construct a cell T
of size G x 1
, where each sub-cell g
is a K^L x L
matrix reporting all the possible L
-tuples from U{1}(g,:)
, U{2}(g,:)
, ..., U{L}(g,:)
.
For example, consider
L=3;
G=5;
K=4;
%U=cell(L,1);
U{1}=randn(5,4);
U{2}=randn(5,4);
U{3}=randn(5,4);
T=cell(G,1);
for g=1:G
U1=U{1}(g,:);
U2=U{2}(g,:);
U3=U{3}(g,:);
[ca, cb, cc] = ndgrid(U1, U2, U3);
T{g} = [ca(:), cb(:), cc(:)];
end
How can I generalise this code to any L
?
I think I could use and modify the answer to this question but I'm struggling to set the input variables.