# Finding index location in volume?

1 回表示 (過去 30 日間)
Syed Abdul Salam 2019 年 9 月 16 日
コメント済み: Syed Abdul Salam 2019 年 9 月 16 日
For instance, I have
x = 2000:0.5:2004; y = 45000:0.3:45009; z = 10:0.2:12;
which are axes of a volume, x has length of 9, y has 31 and z has 11.
Now a volume filled of nan values and given by;
C = rand(9,31,11)*nan;
I want to fill this volume with values when new values come up, it will have x, y, z and the corresponding value. So, I need to find the closest index location and fill the value there. E.g.
x =2002.13, y = 45006.811, z = 11.36 have value of 10000 so i want to fill the corresponding C(x,y,z) = 10000;
here I need to find the index for x = 2002, y = 45006.9, z = 11.4 and fill the value 10000 there in C.
how can I use the values converted to closed index in the volume. Thanks

サインインしてコメントする。

### 採用された回答

Andrei Bobrov 2019 年 9 月 16 日
x = 2000:0.5:2004;
y = 45000:0.3:45009;
z = 10:0.2:12;
x0 = 2002.13;
y0 = 45006.811;
z0 = 11.36;
C = nan(9,31,11);
C0 = 1000;
[~,ii] = min(abs(x - x0));
[~,jj] = min(abs(y - y0));
[~,k] = min(abs(z - z0));
C(ii,jj,k) = C0;
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Syed Abdul Salam 2019 年 9 月 16 日
work perfectly. Thanks

サインインしてコメントする。

### その他の回答 (1 件)

Nicolas B. 2019 年 9 月 16 日
Hi,
x = 2000:0.5:2004; y = 45000:0.3:45009; z = 10:0.2:12;
% no need to use rand() to generate a table of NaN and it's more flexible with automatic size
C = NaN(length(x), length(y), length(z));
pts = [2002.13, 45006.811, 11.36];
[~, xc] = min(abs(x - pts(1)));
[~, yc] = min(abs(y - pts(2)));
[~, zc] = min(abs(z - pts(3)));
C(xc, yc, zc) = my_value;
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Syed Abdul Salam 2019 年 9 月 16 日
Yes, thank you. Both works perfectly.

サインインしてコメントする。

### カテゴリ

Help Center および File Exchange3-D Volumetric Image Processing についてさらに検索

R2019a

### Community Treasure Hunt

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

Start Hunting!

Translated by