I have a matlab script that interpolates to get a new value. So there are two sets of values unique voltage and unique energy. Then there is interpolated voltage which we create by programming
interpolatedVoltage = (3.5:0.01:3.8)';
Then I created interpolatedEnergy from these data using interpolation.
interpolatedEnergy = interp1(uniqueVoltage, uniqueEnergy, interpolatedVoltage, 'linear', 'extrap');
This is how the program works. The program works on 16 sets of data, i.e 16 sets of unique voltage and unique energy to create 16 sets of interpolated energy.The interpolated voltage is same for all 16 sets which we get from the above line of code. Out of 16sets 15 of them are ok, one set is giving some weird values and I am not sure why. So I will share two sets of data, one from one of the correct 15 sets and other the wrong set.
First correct set:
uniqueVoltage = (3.53066775849519 3.53067035022426 .... 3.84681597611049 3.84682177949044)
This is a 9901x1 double array i cant post all the 9901 values here so just giving you an idea.
unique energy = (96.7962090699804 96.7891484740611 96.8032655767983 96.7820835900533 96.8103181481226 96.7750145267493 .................. 0.000557256488020200 0.000728223962312157 0.000106855162461192 0.000749595056905748 0.000429031265910740 0.00113614410430565 0.000407660141488397 0.00111467573818605 0.000364917826072193 0.000386288986801839 0.00154579966056023 0.00152442844457245)
This is also 9901x1 double. Now using the interp1 script we get
interpolatedEnergy = (157.984164074966 130.741363074253 103.498562073598 76.2557610729498 71.6954943796960 64.3493476570002 60.1380167348793 55.5485757108256 50.6952125525250 45.5301211956612 40.1799493512170 34.7333113979099 29.4825451524645 24.5155873829590 19.9779904161105 15.8415077213954 12.0602433779688 8.65701363815505 5.52719951670294 2.64684289203054 0 -2.50079371842751 -4.76824379342714 -6.84830779926775 -8.72701313741007 -10.4254851017059 -12.0755442961229 -13.6163368207559 -15.1435677773727 -16.6638070391892 -18.1993380906739)
These are all the values, which is a 31x1 double. This is correct.
Now I will give you the wrong ones.
uniqueVoltage = (3.54267857142857 3.54267857142857 ..........3.87370393374741 3.87370734126984)
this is a 12128x1 double.
And similarily
uniqueEnergy = (106.670748749771 106.672279230429 106.669217303301 106.667685154779 .......... 0.000715131192799702 0.000984430538650193 0.000828113707411072 0.000737727801595998)
which is also a 12128x1 double.
and then we get interpolated Energy.
interpolatedEnergy = (-73542349778.8076 -56310669477.8076 -39078989176.8076 -21847308875.8076 -4615628575.12006 70.5205235746552 62.4922409998601 58.1823784683028 53.5935342110583 48.2852823614578 42.7415626377397 37.0069009768616 31.3589515760930 26.0188892296641 21.0859020947200 16.6046767621578 12.6165119246077 9.03573575904217 5.80849576891250 2.75148953663250 0 -2.54632248339794 -4.89544569350973 -7.00713946971490 -8.91955065513943 -10.7003376130882 -12.3868240569588 -14.0218867348210 -15.7049306967095 -17.4390479657499 -19.2372152385485)
which is also 31x1 double.
But as you can see from the first 5 values, they are completely off. I dont know why. For all other 15 data its ok. Not everyone starts at 157 like what I shared, but it is close, 120, 100, 96 and values like that are the remaining 15 values. But this one which is wrong is giving such a huge negative values in the beginning and then jumbing to 70. So anyone who knows interpolation very well or the function interp1 very well and how it works, can you please explain why is this happening with this one data. Thank you very much.