While combvec and allcomb seems to both give all combinations of numerical vectors (no idea why there are two functions that does the same thing), neither work for structure vectors. Given an arbitrary number N of structure vectors I would like to generate all possible combinations of them. My end goal is to then merge them (in order to generate combinatorial conditions for a simulation (which I found can be done via https://mathworks.com/matlabcentral/fileexchange/38821-structure-overwrite-and-merge).
An easy way to do this is via nested for loops of course, but that quickly gets out of hand as the number of struct vectors increase, thus I'm looking for a function to do this for an arbitrary number of struct vectors.
Note! Not all structs contain all members. This would leave me to believe I would probably need to use cell arrays to handle the disimilar structures,
a_conditions(1).a = 5;
a_conditions(2).a = 9;
b_conditions(1).b = 2;
b_conditions(1).bextra = "a string";
b_conditions(2).b = 98;
b_conditions(1).bextra = "another string";
b_conditions(3).b = 22;
b_conditions(3).bextra = "something else";
for conds = allcomb(a_conditions, b_conditions, ...
combined = [combined merge(conds(1:end))]
combined(1).a = 5;
combined(1).b = 2;
combined(1).bextra = "a string";
combined(2).a = 5;
combined(2).b = 98;
combined(2).bextra = "another string";
combined(3).a = 5;
combined(3).b = 22;
combined(3).bextra = "something else";
combined(4).a = 9;
combined(4).b = 2;
combined(4).bextra = "a string";
As can be seen, because I need to deal with structures containing non-trivial data types, including scalars, matrices, strings etc, and where some of the conditions might affect multiple variables, I cannot see a reasonable way to rewrite it in terms of allcomb or combvec. Is there anything existing, or do I need to roll my own function for this?