Faster 2D Interpolation?

25 views (last 30 days)
Rod Lopez
Rod Lopez on 2 May 2022
Commented: Rod Lopez on 2 May 2022
I need to interpolate 2D scattered data onto a fine grid. Below is what I am currently doing, and my question is whether there exists a faster a way? Currently my largest data sets (on the order of 3000 x 15000 after up-sampling) take upwards of 7 minutes to run. Preferably this would be a few seconds, but maybe that is asking too much...Similar to my other questions I am unable to provide the exact code for a variety of reasons, but I have listed the steps that I currently perform:
  1. User selects a subset of the input data to view, which is not unifornly spaced.
  2. Generate equally space points using Linspace (based on the max and min values of my input data set)
  3. Create the new grid using Meshgrid
  4. Generate interpolated data set using griddata(old_x,old_y,old_data,new_x,new_y,'nearest')
I have tried running this from a separate function file, from the command window, and as a private function inside my app designer app. They are all very very slow. Would another 2D interpolation technique be better for my appliciation?
Thank you so much!

Answers (1)

Steven Lord
Steven Lord on 2 May 2022
How many times are you performing this interpolation?
Are the old X and Y coordinates the same each time you perform the interpolation, with only the data and the new coordinates changing?
If so consider creating a griddedInterpolant, updating the Values property (but leaving the old coordinate data alone) when you get new data, and evaluating it at each set of new coordinates.
  1 Comment
Rod Lopez
Rod Lopez on 2 May 2022
Hi Steven, thank you for such a quick reply!
The old X and Y coordinates would change each time based on the user's selection. However, for a given data file, it will always end up being a subset of the entire data set. For example, if I load in a data set of size 100 x 100, the user might want to view a 'box' around rows x=50 to 75 and columns y=50 to 75 let's say. I'd then map that onto a rectangular grid using the process I outlined. Small sizes run almost instantly, but once we start getting to large arrays it takes a long time.

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!