Copy subarray with constant "thickness" in one dimension, but varying position
2 次查看(过去 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!