Generate all probability of non repeated combinations of .mat files

1 visualización (últimos 30 días)
M
M el 2 de Mzo. de 2022
Editada: M el 2 de Mzo. de 2022
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?

Respuesta aceptada

Matt J
Matt J el 2 de Mzo. de 2022
Editada: Matt J el 2 de Mzo. de 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 comentarios
M
M el 2 de Mzo. de 2022
Editada: M el 2 de Mzo. de 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
M
M el 2 de Mzo. de 2022
Editada: M el 2 de Mzo. de 2022
@Matt JThank you so much! The code is working now.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Parallel Server en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by