How to simplify IF commands
    5 次查看(过去 30 天)
  
       显示 更早的评论
    
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 个评论
  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
      
      
 2012-7-24
        
      编辑:Jan
      
      
 2012-7-24
  
      if a >= 1 && a <= 8
  T = S(a);
end
3 个评论
  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 Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



