Expand vector along third dimension
    조회 수: 16 (최근 30일)
  
       이전 댓글 표시
    
My question is simply, but I cannot figure out how to do it.
Assume I have a vector K=[K_1,..,K_n] then I would like to create a three dimensional matrix M with first dimension equal to x, second dimension equal to y and third dimension equal to n such that M(:,:,1)=K1*ones(x,y), M(:,:,2)=K2 * ones(x,y) etc. I know of course I can loop, but I am expecting a neat one-liner exists.
댓글 수: 0
채택된 답변
  Matt J
      
      
 2014년 11월 25일
        
      편집: Matt J
      
      
 2014년 11월 25일
  
      I have a matrix S which is x times y. Then I would subtract each element of K (what I wanted to use the extra dimension for), take the positive part (i.e. max of the result and 0) and sum out the first dimension x to get a y times n matrix.
 K=reshape(K,1,1);
 result = squeeze( sum( max(  bsxfun(@minus,S,K), 0), 1 )  )
댓글 수: 1
참고 항목
카테고리
				Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!