Copy subarray with constant "thickness" in one dimension, but varying position
    조회 수: 4 (최근 30일)
  
       이전 댓글 표시
    
I'm trying to copy a subarray from a larger one, within two points in one dimension that always have constant distance, but different position.
Imagine a volume V(x,y,z) with scalar values and a height-map HM(x,y) that maps two dimensions with scalar values describing the z-indices.
A "skin" of constant thickness t sits on top of HM.
How can the subvolume SV(x,y,z) between HM(x,y) and HM(x,y)+t be extracted in the most elegant way, such that the new range of z is between 1 and t?
In a simple approach this can be done by multiple loops and element-wise copying. (Which is not very efficient or parallelized). I am also thinking of building a volume of indices between the HM and HM+t maps to only access the right elements, such that they exactly fill the new orthogonal array. Unfortunately, I have not found a sensible way to do this.
In case this is a too simple question:
For the die hards: What if t  is a map t(x,y) as well? (so that the new subvolume is only sparsely filled between the indices 1 and max(max(t(x,y))) and the rest is NaNs)
댓글 수: 0
답변 (1개)
  Avinash
    
 2022년 12월 7일
        Hi Ianis,
First, you can create a matrix having different positions from where subarrays are supposed be extracted, for example 
     a(1,:)=[x1,y1] ; a(2,:)=[x2,y2] ;................   
Use one for loop to access those positions, keeping a(i,:) as index.To extract the subarray ,for every iteration of for loop for different positions, you can go through the following link of  MATLAB answer to know about extracting a subarray from an array:
Regards   
Avinash 
댓글 수: 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!

