Evaluating all possible combinations

조회 수: 2 (최근 30일)
Michael Jacobson
Michael Jacobson 2023년 3월 6일
댓글: Michael Jacobson 2023년 3월 19일
I am working on designing a composite part. The two main variables are the number of layers i can stack and the orientation of each layer (0,45,90 deg.). In the below image, we can see different layers stacked with different orientations
I am trying to find all possible sequences that can be made, but im not sure how to go about that. For example, if i have 5 layers, how would i determine all the possible sequences?
I've tried perms and nchoosek - don't seem to work, but im not sure why.
Thanks
  댓글 수: 2
Torsten
Torsten 2023년 3월 6일
So for each layer you have 4 possible orientations. Thus if you have N layers, the number of possible arrangements is 4^N. Is this a correct interpretation of what you try to achieve ?
Michael Jacobson
Michael Jacobson 2023년 3월 6일
Yes, i believe that's the proper understanding.

댓글을 달려면 로그인하십시오.

채택된 답변

Karim
Karim 2023년 3월 6일
편집: Karim 2023년 3월 6일
See below for one method to obtain all combinations.
In the resulting matrix, each row represents a combination, the first column holds the angle for the first layers, the second for the second etc.
Hope it helps ;)
% define the angle options for a layer
LayerOptions = [0 -45 45 90];
% define number of layers
NumLayer = 5;
% create place holder for the layers
CellCombo = cell(1,NumLayer);
% assign the options for each layer
CellCombo(:) = {LayerOptions};
% extend the data to obtain the combinations
Combinations = CellCombo;
[Combinations{:}] = ndgrid(CellCombo{:});
Combinations = cell2mat(cellfun(@(m)m(:),Combinations,'uni',0));
% print the result
Combinations
Combinations = 1024×5
0 0 0 0 0 -45 0 0 0 0 45 0 0 0 0 90 0 0 0 0 0 -45 0 0 0 -45 -45 0 0 0 45 -45 0 0 0 90 -45 0 0 0 0 45 0 0 0 -45 45 0 0 0
  댓글 수: 1
Michael Jacobson
Michael Jacobson 2023년 3월 19일
This helps a lot, thanks! It does exactly what I was looking for.
I do appreciate your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by