All combination for a cell structure?
5 次查看(过去 30 天)
显示 更早的评论
Hi all,
I'd like to get all combinations for all elements in a cell structure. For example,
var = rand(20, 3);
no = 5;
numcell = mat2cell(var, size(var, 1)/no*ones(1, no), ones(1, 3));
result in a 5 by 3 cell 'numcell' which contains 4 by 1 double for each cell.
I'd like to find all combinations among 5 by 3 'numcell', performing the calculation numcell{:}*numcell{:}' for each cell element of numcell. So that I'll get all permutation and combination of numcell{i}'*numcell{j}.
Thanks!
采纳的回答
Andrei Bobrov
2016-9-26
编辑:Andrei Bobrov
2016-9-26
I correctly understand:
out = cellfun(@(x)a(:).'*a(:),numcell);
5 个评论
Stephen23
2016-9-26
编辑:Stephen23
2016-9-26
@Xiaohan Du: so what is the point in converting the data to a cell array, when the first step when performing this calculation is to get all the numeric arrays out of the cell array and concatenate them together?
Why bother with the cell array at all, when you don't use it for anything?
Andrei Bobrov
2016-9-26
I am agree with Stephen, just:
a = reshape(var,4,:);
M = a.'*a;
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!