Generate all probability of non repeated combinations of .mat files

1 回表示 (過去 30 日間)
M
M 2022 年 3 月 2 日
編集済み: M 2022 年 3 月 2 日
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
M
M 2022 年 3 月 2 日
編集済み: M 2022 年 3 月 2 日
@Matt JThank you so much! The code is working now.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Parallel Server についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by