3.5

3.5 | 2 ratings Rate this file 13 Downloads (last 30 days) File Size: 6.56 KB File ID: #19687

MATLAB trilinear interpolation

by Mehmet OZTURK

 

23 Apr 2008 (Updated 13 Oct 2008)

A Matlab mex function to perform trilinear interpolation.

| Watch this File

File Information
Description

I'm working with large 3D data and have to interpolate in 3D space. With Matlab's interp3 function my computer hangs because of high memory requirement of vectorized interp3. So i decided to write a mex file to sequencially interpolate the data. There is a speed gain up to 5x.
This function acts as matlab's interp3 function when interp3 is set to linear. However there are some differences. First of all trilinear requires monotonically spaced input grid such as produced by meshgrid. Also trilinear uses zero as extrapolaiton value (can be changed as an input parameter).
This is my first mex code and can be improved such as this code can be en equivalent of interp3.

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
10 Oct 2008 Anders Eklund

Nice work, but your demo program did not work, is it that hard to run the demo program once before you upload it? Changed your demo code a little, you should use a bigger volume to see the difference.

clc
clear

in=round(10*randn(40,30,20));
[y x z]=meshgrid(1:.3:40,1:.2:30,1:.1:20);

start_time1 = clock;
out=interp3(in,x,y,z,'*linear',0);
end_time_1 = clock;
start_time2 = clock;
out2=trilinear(in,x,y,z);
end_time_2 = clock;
err=abs((out) - (out2));
sum(err(:))

time1 = etime(end_time_1,start_time1)
time2 = etime(end_time_2,start_time2)

time_difference = etime(end_time_1,start_time1) - etime(end_time_2,start_time2)

time2/time1

13 Nov 2008 Ning

Hi, I put the trilinear.cpp & trilinear.mexw32 under the folder \MATLAB71\extern\examples\mex, but error 'Undefined command/function 'trilinear'' promotes. Why? because without *.dll?

14 Nov 2008 Mehmet OZTURK

Hi, you have to put the trilinear.mexw32 in a folder that MATLAB searches, for example "work" folder not in \MATLAB7x\extern\examples\mex. I don't know this path is added to matlab by default.

01 Feb 2010 Matt J

Have you ever tried compiling this under LCC? I get a slew of errors when I do. Visual C works fine.

Please login to add a comment or rating.
Updates
28 Apr 2008

Added demo file for usage example

13 Oct 2008

Updated Demo File

Tag Activity for this File
Tag Applied By Date/Time
approximation Mehmet OZTURK 22 Oct 2008 09:58:59
interpolation Mehmet OZTURK 22 Oct 2008 09:58:59
mex Mehmet OZTURK 22 Oct 2008 09:58:59
vectorized Mehmet OZTURK 22 Oct 2008 09:58:59
trilinear Mehmet OZTURK 22 Oct 2008 09:58:59
interpolation Ziyue Chen 22 Oct 2011 05:21:50

Contact us at files@mathworks.com