0

I am trying the understand the logic of what Querying the Interpolant does in matlab and write a logic in c#.

The following code is in matlab.

D = griddedInterpolant(A,B,'linear');

where A=[1;2;3;4;5] B=[6;7;8;9;10]

T=[1;2;3;4;5]

Now when execute the below statement,

D(T)

this is the result I am getting.

ans = [6;7;8;9;10]

I did not understand what is the formula that is producing this result. I found a formula which is as below,

y=((Y2-Y1)(X-X1)/(X2-X1))+Y1

Linear Interpolation Calculation

I did not understood how we calculate using this formula with vector matrix i had.

Could someone please help me what is the formula that we use and how to use.

Siva
  • 1,281
  • 2
  • 19
  • 41
  • You have input that at points `A`, the value is `B`. So why are you confused that when using the input `T` (which is the same as `A`), you get the output `ans` (which is the same as `B`)? There isn't even any interpolation happening here, you're simply doing a lookup, and might as well use `interp1`. From the docs: *"`F = griddedInterpolant(x,v)` creates a 1-D interpolant from a vector of sample points, `x`, and corresponding values, `v`."* – Wolfie Nov 24 '17 at 14:18
  • @Wolfie, Thanks for your reply. The values I have given is just for an example. I want to know how the calculation is done. "interp1" can be used in matlab. My problem is I am writing an equivalent logic in c-sharp. That is the reason I want to know how the calculations are done. – Siva Nov 27 '17 at 05:12

0 Answers0