Interpolation to map from constant step size in X over to constant step size in Y with 2D arrays

11 views (last 30 days)
Hi - I've been trying to think about the most elegant (fastest) way to execute the following procedure.
First is the process in general I am trying to achieve: I have an X,Y dataset where X is evenly spaced and Y represents the output of a particular function. I want to remap this to evenly spaced Y and function dependent X. I've been doing this using the interp1 function - seems pretty standard:
X = [1:5:100];
Y = 0.01 * Y.^2;
X2 = [min(Y):(max(Y)-min(Y))/20:max(Y)];
Y2 = interp1(Y,X,Y2,'linear','extrap');
The real problem I am facing is that X and Y in my application are actually both 2D arrays. The "x,y pairings" are such that Row 1 of X and Row 1 of Y represent an X,Y space that I want to remap from constant steps in X to constant steps in Y. So I need to do this interpolation procedure on each row individually. There is no common X to go with the multi-dimensional output Y, so the built-in multi-dimensional support for interp1 doesnt seem to apply.
Up to now, I have been using a FOR loop to step through each row and individually interpolate. It is unbearingly slow for large datasets. I think I could improve my code by minimizing the use of variable instantiation for handling each row, but I am thinking there might be a better way to do this in a true matrix operation anyway. I only need very simple linear interpolation, I might even be OK with a "nearest neighbor" approach because the dataset is quite dense unlike my example.
Any ideas?
Thanks a bunch, this community is great!

Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!