If vs Switch Case
이전 댓글 표시
I just started coding earlier this year, and I am trying to figure out when to use certain functions. I currently have a series of 9 if/else statements, and I was wondering if it would be more efficient or if there is a reason to use switch/case over my current if else statements. P is a 9x9x9 3D matrix and C[] is a 3x3 matrix
if true
% code
if (1<= i && i<=3) && (1<= j && j<=3)
f = ismember(P(j,k,i),C1);
elseif (1<= i && i<=3) && (4<= j && j<=6)
f = ismember(P(j,k,i),C2);
elseif (1<= i && i<=3) && (7<= j && j<=9)
f = ismember(P(j,k,i),C3);
elseif (4<= i && i<=6) && (1<= j && j<=3)
f = ismember(P(j,k,i),C4);
elseif (4<= i && i<=6) && (4<= j && j<=6)
f = ismember(P(j,k,i),C5);
elseif (4<= i && i<=6) && (7<= j && j<=9)
f = ismember(P(j,k,i),C6);
elseif (7<= i && i<=9) && (1<= j && j<=3)
f = ismember(P(j,k,i),C7);
elseif (7<= i && i<=9) && (4<= j && j<=6)
f = ismember(P(j,k,i),C8);
else
f = ismember(P(j,k,i),C9);
end
if f == 1
P(j,k,i) = 0;
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!