简体   繁体   English

3D体积索引以获取任意向量Matlab

[英]3D volume indexing to get arbitrary vectors matlab

I have a 3D volume and a list of x,y coordinates. 我有一个3D体积和一个x,y坐标列表。 I need to extract from the volume all vectors 我需要从体积中提取所有向量

V(x,y,:)

turned x,y to linear index but I cannot use: x,y为线性索引,但是我不能使用:

V(ind,:) 

because Matlab assumes that ind is a subscript and I get an error (index exceeded...). 因为Matlab假设ind是下标,并且出现错误(索引已超出...)。 It's OK to use V(:,ind) but that's not what I need. 可以使用V(:,ind)但这不是我所需要的。

Any way of doing this without repmat on the 3rd dimension and use linear index on all three dimensions? 有没有办法在第三个维度上没有repmat并在所有三个维度上都使用线性索引? I want to avoid this, because the volume is very large. 我想避免这种情况,因为体积很大。

You can use permute to rearrange your data matrix 您可以使用permute来重新排列数据矩阵

 V2 = permute(V, [3 1 2]);

Then you can access the (former) z-data by V2(:,ind) , ie, V(x,y,:) would give the same result as V2(:,ind) . 然后,您可以通过V2(:,ind)访问(以前的)z数据,即V(x,y,:)会得到与V2(:,ind)相同的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM