MATLAB: Is the griddedInterpolant not working properly

griddedinterpolantmatrix interpolationsurf

Hi, I am kind of new to matlab, for the purpose of interpolating 3D tables I use the function griddedInterpolant. If I plot the original table using surf, it looks totally wrong if I compare it with the griddedInterpolant plot, can someone explain what I did wrong?
I have a 10×10 matrix of sample points: DUR5 =
Columns 1 through 8
2.1300 6.0900 7.0100 7.5200 8.0600 8.8100 9.7300 10.4300
1.9200 5.8600 6.7700 7.3100 7.9500 8.6000 9.5200 10.2000
1.5000 5.7400 6.4000 7.0300 7.7800 8.4100 9.3500 9.9800
0.1400 5.0900 6.0000 6.4700 7.1000 8.0400 9.1400 9.8400
-0.1900 5.0400 6.0500 6.4700 7.0800 8.0400 9.0200 9.8900
-0.3700 5.0400 5.9500 6.5200 6.9800 7.6600 9.0200 10.2900
-0.8000 4.4300 5.7000 6.3000 6.6800 7.3400 8.8100 10.2200
-1.2900 3.8900 5.3000 5.9800 6.6300 7.3400 8.6500 10.3600
-2.0200 3.6600 4.7600 5.3900 6.4200 7.3600 8.9800 10.5000
-2.2300 1.6200 3.3300 4.7800 5.2300 6.1200 8.4800 10.6200
Columns 9 through 10
11.3200 12.3000
11.0400 11.9100
10.7300 11.6000
11.1300 12.2800
11.1100 12.0900
11.3700 12.6100
11.7200 12.6300
11.9800 13.5900
12.3700 13.3800
12.3700 14.3700
X-axis: MGSTR =
0 2 4 5 7 10 15 20 25 30
Y-axis: RPM =
Columns 1 through 7
0 150 550 900 1000 1250 1500
Columns 8 through 10
1750 2000 2500
F=griddedInterpolant({MGSTR,RPM},DUR5)
F =
griddedInterpolant with properties:
GridVectors: {[0 2 4 5 7 10 15 20 25 30] [1x10 double]}
Values: [10x10 double]
Method: 'linear'
ExtrapolationMethod: 'linear'
The normal plot is given by the folling command: surf(MGSTR, RPM, DUR5) For the gridded plot I make a mesh: Xi=0:1:30 Yi=0:50:2500 [X,Y]=ndgrid(Xi,Yi) and then plot the gridded version: surf(X,Y,F(X,Y))
It look like it is some sort of mirrored image. Can anybody please help?

Best Answer

You need to transpose your DUR5 matrix when you use griddedInterpolant because you are giving it X and Y vectors, but your matrix is actually Y,X because it is rows first then columns as 2nd dimension. This is something that always catches me out and confuses me when going between an X, Y space and a rows, columns space of matrix data.
i.e.
F=griddedInterpolant({MGSTR,RPM},DUR5')