Combine Vectors Into Matrix - NOT ALL Possible Combinations from baseline

1 vue (au cours des 30 derniers jours)
AJ Foyt
AJ Foyt le 10 Fév 2019
Commenté : AJ Foyt le 13 Fév 2019
Hello All,
I have come across ways of combining vectors into a single matrix with all possbile matrices, however I am looking to step through changes for a DOE for example, so order matters and I only want to change one parameter at a time.
So if I have
A = {1, 2, 3, 4};
B = {7, 8, 9};
C = {10, 11, 12, 13};
D = {14, 15, 16};
It would yeild
Consider { 1 7 10 14} as a "baseline" and then the full DOE would look like...
The number of vectors would be dynamic and the length of the vectors as well.
Combs = 1 7 10 14
2 7 10 14
3 7 10 14
4 7 10 14
1 8 10 14
1 9 10 14
1 7 11 14
1 7 12 14
1 7 13 14
1 7 10 15
1 7 10 16
Any syntax help is greatly apperciated!
  2 commentaires
Mark Sherstan
Mark Sherstan le 10 Fév 2019
Have you considered using the built in DOE functions? fullfact and fracfactgen might be useful. More info here: https://www.mathworks.com/help/stats/design-of-experiments-1.html
AJ Foyt
AJ Foyt le 10 Fév 2019
Thank you Mark, That is an interesting toolbox I was not aware of. Unfortunately I do not have the licensing for that toolbox.

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 11 Fév 2019
Modifié(e) : Guillaume le 11 Fév 2019
allpoints = {[1 2 3 4], [7 8 9], [10 11 12 13], [14 15 16]}; %can be as many vectors of any length
baseline = [1 7 10 14];
assert(isequal(size(baseline), size(allpoints)), 'Shape and size of baseline doesn''t match allpoints');
assert(all(cellfun(@ismember, num2cell(baseline), allpoints)), 'Some points in baseline are not in allpoints');
result = cell(size(allpoints));
for vecidx = 1:numel(allpoints) %iterate over the test vectors
testmatrix = repmat(baseline, numel(allpoints{vecidx}), 1); %replicate baseline to number of elements in current vector
testmatrix(:, vecidx) = allpoints{vecidx}(:); %and replace test column by all the points in that vector
result{vecidx} = testmatrix;
end
result = vertcat(result{:}) %concatenate the whole lot
Generates only the required combinations so should be a lot faster than generating all combinations and then discarding the unwanted ones.
  2 commentaires
Stephan
Stephan le 11 Fév 2019
Just recognized that my approach would fail in cases where the content of allpoints is repeated in some entries. Nice solution!
AJ Foyt
AJ Foyt le 13 Fév 2019
Thank you Guillaume!!! That is a perfect solution.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by