Is there something like 'array colon'? in other words how can I apply colon operator to all the elements of an array (please read the text below so my question will make sense)?
    조회 수: 7 (최근 30일)
  
       이전 댓글 표시
    
A = [1 10 16 23];
A-3:A+2 will result in [-2,-1,0,1,2,3]; In other words colon operates only on the first element of array A. However I want to apply A-3:A+2 on all the elements of A; I know I can get this by a loop, like :
u=[];for i=1:4, u=[u,A(i)-3:A(i)+2]; end
However I wonder if there is a way to do this without using loop. (The actual array I am working with is too long to loop through it.)
This sounds like a super simple question but I have no ides how to do it in a simple way (other than looping).
I so much appreciate any help.
댓글 수: 0
채택된 답변
추가 답변 (3개)
  Azzi Abdelmalek
      
      
 2012년 10월 28일
        
      편집: Azzi Abdelmalek
      
      
 2012년 10월 28일
  
      do you mean a division
A = [1 10 15 23]; 
(A-3)./(A+2 )
댓글 수: 4
  Azzi Abdelmalek
      
      
 2012년 10월 28일
				
      편집: Azzi Abdelmalek
      
      
 2012년 10월 28일
  
			I'm not sur what you need
A = [1 10 15 23]; 
unique(cell2mat(arrayfun(@(x)  x-3:x+2,A,'un',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!