Clear Filters
Clear Filters

Generate all probability of non repeated combinations of .mat files

1 view (last 30 days)
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?

Accepted Answer

Matt J
Matt J on 2 Mar 2022
Edited: Matt J on 2 Mar 2022
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 Comments
M
M on 2 Mar 2022
Edited: M on 2 Mar 2022
@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

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Parallel Server in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!