필터 지우기
필터 지우기

How to simplify IF commands

조회 수: 1 (최근 30일)
Aadil
Aadil 2012년 7월 24일
How can I simplify this?
if a==1; T=S(1); end
if a==2; T=S(2); end
if a==3; T=S(3); end
if a==4; T=S(4); end
if a==5; T=S(5); end
if a==5; T=S(5); end
if a==6; T=S(6); end
if a==7; T=S(7); end
if a==8; T=S(8); end
Thanks
  댓글 수: 2
Aadil
Aadil 2012년 7월 24일
bump
Jan
Jan 2012년 7월 24일
Please, Aadil, do not bump a question after half an hour. The voluntary contributors in the forum answer as fast as possible already, such that it would be more friendly to limit bumping to at least 24 hours.

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

채택된 답변

Jan
Jan 2012년 7월 24일
편집: Jan 2012년 7월 24일
if a >= 1 && a <= 8
T = S(a);
end
  댓글 수: 3
Aadil
Aadil 2012년 7월 24일
Worked perfect thanks, seems I was missing the obvious
Daniel Shub
Daniel Shub 2012년 7월 24일
@Andrei, if a is greater than 8, then the example in the question and Jan's answer result in T being undefined, while in your answer, T becomes empty.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by