Permutation of specific strings in switch cases and test on what is put in locations (the strings)
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Nicle Davidson
il 9 Set 2021
Commentato: Nicle Davidson
il 9 Set 2021
I have called this post for permutation in switch, but I am not sure that it was the right title for the question.
I have three strings such as:
A='abcdh' ;
B='efghn';
C='ijklm ';
I have also a matrix of permutated '123' such as U = perms('123');
I run to a for-loop to test all U's
and in that for-loop for each element in U, I need to do something
something is:
I need to for the first element of U, say it is '321',
put A,B,C in three different locations.
like
location1 = A;
location2 = B;
location3 = C;
and then I need to do a test with what is in these locations, after the test then I need to change what I put in these locations like:
location1 = B;
location2 = C;
location3 = A;
and again do all tests on what is in these locations.
and then after that change what I put in these locations again, do this until all
'CBA'
'CAB'
'BCA'
'BAC'
'ACB'
'ABC'
have participated in the test. After that then I need to do the whole round with the next element in the U matrix.
'321'
'312'
'231'
'213'
'132'
'123'
Say the test is done with '321' then do all that with '312' etc.
I could guess that I should start with a switch such as: (or a for-loop could be better? i guess)
switch U
case ...%the first element of U
%put A,B,C in new locations
%do the test on what is put (those strings) in those locations
% test the next element in U matrix I guess by going to the next case
case
...
end
*The test shall be done on the strings which are defined in the first place.
But some how I need help to set this up
any idea would be appriciated.
1 Commento
Lawrence
il 9 Set 2021
With a switch statement, you only get to run one case. And it's the entire U (not each row) that gets tested against the cases when choosing which one to run.
Risposta accettata
Lawrence
il 9 Set 2021
Modificato: Lawrence
il 9 Set 2021
I'd do this with nested for loops, using perms() a second time to go through the locations:
A='abcdh';
B='efghn';
C='ijklm';
U = perms('123');
locations = perms({A B C})
for i = 1:size(U,1)
for j = 1:size(locations,1)
u = U(i,:);
location1 = locations{j,1};
location2 = locations{j,2};
location3 = locations{j,3};
%Perform test here
end
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Testing Frameworks in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!