Extract value from a 3D array with interpolation

I have a 3D array with row (row_ID), column (col_ID) and Z (z_ID) identifiers.
Essentially what I need is:
  1. For a particular (row_ID, col_ID, z_ID), return the data value stored at that location.
  2. If the (row_ID, col_ID) are not integers, then perform an interpolated value. z_ID will always be an integer.
Thank you

回答 (1 件)

KSSV
KSSV 2017 年 2 月 7 日

0 投票

load data.mat ;
A = gim_tec ;
[m,n,p] = size(A) ;
x = 1:n ;
y = 1:m ;
[X,Y] = meshgrid(x,y) ;
%%pick series if integer
row = 2 ;
col = 3 ;
iwant = zeros(1,p) ;
for i = 1:p
iwant(i) = A(row,col,i) ;
end
%%If fractions
row = 1.5 ;
col = 7.5 ;
iwant1 = zeros(1,p) ;
for i = 1:p
iwant1(i) = interp2(X,Y,A(:,:,i),row,col) ;
end

8 件のコメント

BenL
BenL 2017 年 2 月 7 日
Hi KSSV
Thank you for the response, how do I input the desired row, column and Z values? Do i edit the row= and col= ? What about the Z value?
KSSV
KSSV 2017 年 2 月 7 日
Yes row and col is your desired row_ID, col_ID and z value is what you find i.e iwant.
BenL
BenL 2017 年 2 月 7 日
where do I input the 3rd dimension? say if I want to return the value stored at row_ID = 20, col_ID = 30, Z = 12 (i.e. 20,30,12)?
KSSV
KSSV 2017 年 2 月 7 日
編集済み: KSSV 2017 年 2 月 7 日
This gives only one output.....A(20,30,12).
Third dimension is the one you seek/ find for given row_id and col_id. For a given id's you will get respective z values which are 25 in number.
BenL
BenL 2017 年 2 月 7 日
Oh i see! Just wondering, is it possible to interpolate using a surface instead of a linear interpolation scheme?
Walter Roberson
Walter Roberson 2017 年 2 月 7 日
KSSV
KSSV 2017 年 2 月 7 日
interp2 is not linear ...Read documentation...As suggested by Walter have a look into griddedInterpolant.
Walter Roberson
Walter Roberson 2017 年 2 月 7 日
interp2 defaults to linear, but there are some options

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

カテゴリ

タグ

質問済み:

2017 年 2 月 7 日

編集済み:

2017 年 2 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by