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 CenterFile Exchange 中查找有关 Get 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