2017-05-15 75 views
0

我有一個MATLAB 3D矩陣,我想要在第三維插值。我使用MATLAB interp3做到這一點:使用Matlab interp3而不先調用meshgrid

final_3D_mat=interp3(hor_inds_mm, vert_inds_mm, prev_depth_axis_mm,... 
         prev_3D_mat, ... 
         hor_inds_mm, vert_inds_mm, new_depth_axis_mm) 

所使用的數組的大小:

size(prev_3D_mat) 
size(hor_inds_mm) 
size(vert_inds_mm) 
size(prev_depth_axis_mm) 
size(new_depth_axis_mm) 

ans = 
    337 507 17 
ans = 
    1 507 
ans = 
    1 337 
ans = 
    1 17 
ans = 
    1 337 

我不想叫meshgrid調用之前interp3,並使用X,將interp3的Y,Z參數作爲向量。不過,我不斷收到一個錯誤信息:

??? Error using ==> interp3 at 128 
XI,YI, and ZI must be the same size or vectors of different 
orientations. 

我想交換的hor_inds_mm和vert_inds_mm參數的地方,但得到的錯誤:

??? Error using ==> interp3 at 128 
The lengths of X,Y and Z must match the size of V. 

我也試圖改變,如矢量的方向這樣的:

final_3D_mat=interp3(hor_inds_mm, vert_inds_mm', permute(prev_depth_axis_mm,[1 3 2]),... 
         prev_3D_mat, ... 
         hor_inds_mm, vert_inds_mm',permute(new_depth_axis_mm,[1 3 2])); 

但我得到了同樣的錯誤:

??? Error using ==> interp3 at 128 
XI,YI, and ZI must be the same size or vectors of different 
orientations. 

有人可以幫忙嗎?

回答

0

你是接近成功,只是需要讓前兩個指數的不同方向:

final_3D_mat=interp3(hor_inds_mm', vert_inds_mm, prev_depth_axis_mm,... 
         prev_3D_mat, ... 
         hor_inds_mm', vert_inds_mm, new_depth_axis_mm) ; 
+0

這樣做,我得到的錯誤:???錯誤使用==> interp3 at 128 X,Y和Z的長度必須與V的大小相匹配。 – user4861528

+0

我們以不同的方式定義變量。我只是按照你的方式更新了答案,現在它應該可以工作。 –

+0

非常感謝!它確實工作! – user4861528