How can list All possible modes

4 visualizaciones (últimos 30 días)
Amy Hs
Amy Hs el 13 de Mzo. de 2019
Respondida: Sameer el 14 de Mayo de 2025
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

Respuestas (1)

Sameer
Sameer el 14 de Mayo de 2025
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!

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by