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
Andrei Bobrov 2016년 9월 26일
편집: Andrei Bobrov 2016년 9월 26일

2 개 추천

I correctly understand:
out = cellfun(@(x)a(:).'*a(:),numcell);

댓글 수: 5

Xiaohan Du
Xiaohan Du 2016년 9월 26일
Hi Andrei,
Sorry for my explanation, the 'out' is not what I wanted. I meant all permutation and combinations of cells in numcell.
I've corrected my question, please see it.
Andrei Bobrov
Andrei Bobrov 2016년 9월 26일
편집: Andrei Bobrov 2016년 9월 26일
Maybe as?
a = cat(2,numcell{:});
M = a.'*a;
Xiaohan Du
Xiaohan Du 2016년 9월 26일
I think this is it! Thanks a lot!
Stephen23
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?
I am agree with Stephen, just:
a = reshape(var,4,:);
M = a.'*a;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

질문:

2016년 9월 26일

댓글:

2016년 9월 26일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by