Interpolation between three sets of data

I have three Arrays(Column Vector?) of Speed vs. Position for three different voltages (9V, 13.5V and 16V). Each array contains a speed for every position (2387 values). I would like to make a lookup table with the position and voltage as inputs and the speed value as output. For that, I would like to interpolate the speed vs. position arrays for the voltages in between the three that I already have. That should result in speed vs position arrays for 9v, 10v, 11v - 16v. Is this possible?
The interpolation methods in the help section only show how to interpolate along the x-axis (in this case the Position values) while in my case, I have three sets of data separated by voltage and want to interpolate in between these sets.
Perhaps a multidimensional array could be used?
Any help would be greatly appreciated.

 Accepted Answer

Let your data S (Speed) V (voltages):
V = [9, 13.5, 16];
S = randi(20,10,3);
Solution:
n = 1:size(S,1);
[ii,jj] = ndgrid(n,V);
F = griddedInterpolant(ii,jj,S,'cubic');
[i2,Vnew] = ndgrid(n,[9 10 11 16]);
out = F(i2,Vnew);
or with griddata:
n = 1:size(S,1);
[ii,jj] = ndgrid(n,V);
[i2,Vnew] = ndgrid(n,[9 10 11 16]);
out = griddata(ii,jj,S,i2,Vnew);

5 Comments

Thank you for your answer. I have a question though.
for S, should I replace randi(20,10,3); with my three variables corresponding with 9 13.5 and 6 from the workspace?
I tried that and my "out" was filled with NAN's.
Could you perhaps explain your solution so that I understand what is being done at each step?
Also, matlab gave the following errors:
"Error using griddedInterpolant The grid vectors do not define a grid of points that match the given values."
"Warning: The 'cubic' method requires the grid to have a uniform spacing. Switching the method from 'cubic' to 'spline' because this condition is not met."
Thank you in advance!
EDIT:
I got it to work with your edit with griddata! Thank you very much!
Please try variant with griddata. Now I do not have access to MATLAB, only an Octave. And please attach example of your data.
Okay, I have now interpolated the data from 9-16V in increments of 0.5V. I have done this for 25C, -20C and 85C. Now I wish to interpolate in the same method but in the third dimension in order to get a 4d matrix.
I have this so far:
V = [9, 13.5, 16];
SRT = [RT9VCor,RT13_5VCor,RT16VCor];
SLT = [LT9VCor,LT13_5VCor,LT16VCor];
SHT = [HT9VCor,HT13_5VCor,HT16VCor];
n = 1:size(SRT,1);
[ii,jj] = ndgrid(n,V);
[i2,Vnew] = ndgrid(n,[9 9.5 10 10.5 11 11.5 12 12.5 13 13.5 14 14.5 15 15.5 16]);
RTout = griddata(ii,jj,SRT,i2,Vnew);
LTout = griddata(ii,jj,SLT,i2,Vnew);
HTout = griddata(ii,jj,SHT,i2,Vnew);
Everything above works so far. Now I want to interpolate these results for the different temperatures.
T = [-20, 25, 85];
S = cat(3,LTout,RTout,HTout);
n1 = 1:size(S,1);
[ii1,jj1] = ndgrid(n1,T);
[i21,Tnew] = ndgrid(n,-20:1:85);
Vout = griddata(ii1,jj1,S,i21,Tnew);
Since I dont quite understand what the ii and jj are doing, I also dont know how to adjust them for a third dimension. The griddata also needs to be adjusted but I dont know what to change. These are the error messages:
"Error using griddata (line 93) X,Y and XI,YI cannot be arrays of dimension greater than two."
"Error in Data_Analysis (line 56) Vout = griddata(ii1,jj1,S,i21,Tnew);"
(The Data itself consists of RPM values per mm. There are 2387 data points which correspond to the Position and each point has an RPM value)
Thank you in advance.
n = 1:size(SLT,1);
[i0,j0,k0] = ndgrid(n,[9,13.5,16],[-20,25,85]);
S = cat(3,SLT,SRT,SHT);
[i1,j1,k1] = ndgrid(n,9:.5:16,-20:85);
Vout0 = griddatan([i0(:),j0(:),k0(:)],S(:),[i1(:),j1(:),k1(:)]);
Vout = reshape(Vout0,size(i1));
Thank you very much!
I spent most of yesterday afternoon and this morning trying to figure this out by reading the help section and using trial and error.
I got close enough to know the griddatan needed a 2387x15x106 values but I didnt know how to use ndgrid to achieve this. Thanks again for your solution.

Sign in to comment.

More Answers (1)

Hi, Interpolation can also be done for multidimensional data. Please refer to the documentation page for INTERP2 and INTERP3 at the following locations:
and

Categories

Find more on Interpolation 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!