Generate all probability of non repeated combinations of .mat files

1 次查看(过去 30 天)
How can I generate all probability of non repeated combinations of .mat files.
For exapmle there are the following mat files : One.mat , Two.mat , Three.mat
and each of these files contains 2 vector for example: One.mat contains V1 and V2 vectors, Two.mat: contains C1 and C2 vectors , Three.mat: contains D1 and D2 vectors.
So I want to generate the following combinations:
Comb1.mat contains: One.mat and Two.mat
Comb2.mat contains: One.mat and Two.mat
Comb3.mat contains: Two.mat and Three.mat
Comb4.mat contains: One.mat ,Two.mat and Three.mat
Is there any code can help me to achieve this?

采纳的回答

Matt J
Matt J 2022-3-2
编辑:Matt J 2022-3-2
names=["One","Two","Three"];
N=numel(names);
combs=cell(N,1);
for i=1:N
combs{i}=num2cell(nchoosek(1:numel(names),i),2);
end
combs=vertcat(combs{:});
N=size(combs,1);
for i=1:N
S=arrayfun(@load, names(combs{i}) ,'uni',0);
args=cellfun(@namedargs2cell, S,'uni',0) ;
args=[args{:}];
S=struct(args{:});
save("Comb"+i,'-struct','S')
end
  5 个评论
M
M 2022-3-2
编辑:M 2022-3-2
@Matt J thank you, the error is solved but this code gave just 2 combinations . Can you please edit the code so it can gave all possibility of combinations.
This combination is missed : Comb4.mat contains: One.mat ,Two.mat and Three.mat

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Parallel Server 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by