Effacer les filtres
Effacer les filtres

Copy subarray with constant "thickness" in one dimension, but varying position

1 vue (au cours des 30 derniers jours)
Ianis Unterhuber
Ianis Unterhuber le 10 Jan 2021
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)

Réponses (1)

Avinash
Avinash le 7 Déc 2022
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

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by