MATLAB Answers

permutation matrix for process simulation

3 ビュー (過去 30 日間)
bruno ebel
bruno ebel 2020 年 2 月 27 日
コメント済み: bruno ebel 2020 年 2 月 28 日
I'd like to test the combined effect of different filtration unit (diafiltration, ultrafiltration,...) and used them in different order. For now I have a manual code that works with a small number of unit filtration, but I would like to find something more generic and that would work with a N filtration units. For that, I need a matrix that contains the different possibilities.
The idea is to test firstly all the filtration units separately and then combine them gradualy while permuting the order.
Separator 1
Separator 2
Separator 1 / Separator 2
Separator 2 / Separator 1
Separator 1 / Separator 3
Separator 1 / Separator 2 / Separator 3
a=1; %Separator1
b=2; %Separator2
c=3; %Separator3
d=4; %Separator4
the results I need is that:
1 0 0 0
2 0 0 0
3 0 0 0
4 0 0 0
2 1 0 0
1 2 0 0
3 1 0 0
1 3 0 0
4 1 0 0
1 4 0 0
3 2 0 0
thanks by advance,

  0 件のコメント

サインイン to comment.


Jon 2020 年 2 月 27 日
編集済み: Jon 2020 年 2 月 27 日
You should be able to loop using perms and nchoosek to do what you need.
Something like this:
% generate filtration test matrix
numFilters = 4
filters = 1:numFilters
A = [];
for i = 1:numFilters
% generate a matrix with all the ways of choosing the current number of filters
C = nchoosek(filters,i);
% loop through each of the possible ways of choosing this many filters
for j = 1:size(C,1);
% get all of the permutations of the current selection
B = perms(C(j,:));
Z = zeros(size(B,1),numFilters-size(B,2));
% add the new block of permutations and an appropriately sized block of zeros
A = [A;[B Z]];
By the way, I think in your manual code you forgot the permutations of [1 3 4] ie perms([a,c,d])
The above code grows the A matrix in a loop, rather than having it preallocated as is recommended for better memory management/performance. If the performance mattered you could probably work out how many rows A will have in advance and preallocate it, but the combinatorics were a little daunting :)

  4 件のコメント

表示 1 件の古いコメント
Stephen Cobeldick
Stephen Cobeldick 2020 年 2 月 28 日
"just a last question about that, do you know if it's possible to have a matrix with the unit names directly in it?"
Use a table:
Jon 2020 年 2 月 28 日
Hi Bruno, Glad to hear that this code did exactly what you wanted. Hopefully you can combine it with Stephen's suggestion to use a table to have the unit names directly in it. If this answers your question, when you have a chance it would be good to "accept" the answer. This way others who may have a similar problem will know that an answer is available
bruno ebel
bruno ebel 2020 年 2 月 28 日
Ok thanks a lot, i will test the table.
thanks again,

サインイン to comment.

その他の回答 (0 件)

サインイン してこの質問に回答します。

Translated by