How can list All possible modes

4 ビュー (過去 30 日間)
Amy Hs
Amy Hs 2019 年 3 月 13 日
回答済み: Sameer 2025 年 5 月 14 日
Hi guys,
I have 2 kind of streams "HOT" and "COLD"
I want to consider all the possible modes that these streams can face each other,
means for example for 2 hot streams and 2 cold streams (h1 h2 and c1 c1)
it is important that which one face another and where,
consider a grid
case 1 : h1 vs c1 then h1 vs c2 and h2 vs c1 then h2 vs c2
case 2 : h1 vs c2 then h2 vs c1 and h1 vs c2 then h1 vs c1
case 3 : h2 vs c1 then h2 vs c2 and h1 vs c1 then h1 vs c2
case 4 : h2 vs c2 then h1 vs c1 and h2 vs c2 then h2 vs c1
these the all cases could happen ( m*n cases not n*n)
i hope explained it well,
could you help me how order matlab to do it?
sorry for my bad english

回答 (1 件)

Sameer
Sameer 2025 年 5 月 14 日
If you have m hot streams and n cold streams, and you want to list all possible ways each hot stream can face the cold streams in any order, you can use permutations. For example, with 2 hot (h1, h2) and 2 cold (c1, c2) streams, here’s a simple MATLAB code to generate all possible cases:
m = 2; % number of hot streams
n = 2; % number of cold streams
cold_perms = perms(1:n); % all possible orders for cold streams
num_cases = size(cold_perms, 1)^m;
cases = zeros(m, n, num_cases);
counter = 1;
for i = 1:size(cold_perms,1)
for j = 1:size(cold_perms,1)
cases(:,:,counter) = [cold_perms(i,:); cold_perms(j,:)];
counter = counter + 1;
end
end
% Display all cases
for k = 1:size(cases,3)
fprintf('Case %d:\n', k);
for h = 1:m
fprintf(' h%d vs c%d then h%d vs c%d\n', h, cases(h,1,k), h, cases(h,2,k));
end
end
For more information, Please refer the following MathWorks documentation link:
Hope this helps!

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by