Permutation of specific strings in switch cases and test on what is put in locations (the strings)

1 次查看(过去 30 天)
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 个评论
Lawrence
Lawrence 2021-9-9
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.

请先登录,再进行评论。

采纳的回答

Lawrence
Lawrence 2021-9-9
编辑:Lawrence 2021-9-9
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
  1 个评论
Nicle Davidson
Nicle Davidson 2021-9-9
I think this code should work, please let me test, it will take a bit time, but I think this will work, I will come back here and click on accept when tested, and yes, the test will run the same test code. And yes for loop is suited better I see for this case. I will come back and click on accepted when I test it. I appreciate your time and effort.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Testing Frameworks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by