Can I execute only one case inside multiple cases inside switch ?

조회 수: 1 (최근 30일)
omar th
omar th 2023년 5월 3일
댓글: omar th 2023년 5월 3일
The code below is execution the cases randomly, for example in the first round 3 1 2 in the second round 2 1 3 and so forth. my question can I execute only one case each round, for example in the first round case 2 is executed and in the second round selecting case 1 and so forth. ?
thanks in advance
for jj=1:20
for randCases=randperm
switch randCases
case 1
for best_1
for i_1
do calculation
end
end
case 2
for best_2
for i_2
do calculation
end
end
case 3
for best_3
for i_3
do calculation
end
end
end
end
end

채택된 답변

VBBV
VBBV 2023년 5월 3일
Yes, you can execute it single case from each round by adding an extra for loop
% define round sequence
randCases=randperm(3,3)
randCases = 1×3
1 3 2
% add an extra loop
for k = 1:length(randCases)
switch randCases(k)
case 1
for best_1
for i_1
do calculation
end
end
case 2
for best_2
for i_2
do calculation
end
end
case 3
for best_3
for i_3
do calculation
end
end
end
end
  댓글 수: 1
omar th
omar th 2023년 5월 3일
First thank you for your response, But this way exactly works same as the way in my question code...My question was if I could select only one case, the round that I mean is round of the outer loop
for jj
end
this is the outer loop my question was If I could execute a single case randomly each round, for example when jj =1 select case 2 and when jj=2 select case 3 and spo forth...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by