MATLAB: Curve fitting function not able to reproduce curve accurately

coefvalscurve fitting

Struggling to get the coefvals for a 2D Poly curve to accurately reproduce the curve as expected
Code example as follows:
clear; clc;
%% some input Data
id_cont = [-800,-799,-798,-797,-796,-795,-794,-793.876319759898,-793,-792,-791,-790,-789,-788,-787,-786,-785,-784,-783,-782,-781,-780,-779.221198939486,-779,-778,-777,-776,-775,-774,-773,-772,-771,-770,-769,-768,-767,-766,-765,-764,-763,-762,-761,-760.226570227913,-760,-759,-758,-757,-756,-755,-754,-753,-752,-751.650880397759,-751,-750,-749,-748,-747,-746,-745,-744,-743,-742.351206930442,-742,-741,-740,-739,-738,-737,-736,-735,-734,-733,-732.015232298435,-732,-731,-730,-729,-728,-727,-726,-725,-724,-723,-722,-721,-720.416227090495,-720,-719,-718,-717,-716,-715,-714,-713,-712.931512361220,-712,-711,-710,-709,-708,-707,-706,-705.150524888701,-705,-704,-703,-702,-701,-700,-699,-698,-697,-696.838003819545,-696,-695,-694,-693,-692,-691,-690,-689,-688,-687.923006242512,-687,-686,-685,-684,-683,-682,-681,-680,-679,-678.845793132120,-678,-677,-676,-675,-674,-673,-672,-671.856064708361,-671,-670,-669,-668,-667,-666,-665,-664.526539695457,-664,-663,-662,-661,-660,-659,-658,-657,-656.824360559143,-656,-655,-654,-653,-652,-651,-650,-649,-648.709218964540,-648,-647,-646,-645,-644,-643,-642,-641,-640.134815115666,-640,-639,-638,-637,-636,-635,-634,-633.212240644420,-633,-632,-631,-630,-629,-628,-627,-626.046119965578,-626,-625,-624,-623,-622,-621,-620,-619,-618.579222522835,-618,-617,-616,-615,-614,-613,-612,-611,-610.784258800584,-610,-609,-608,-607,-606,-605,-604,-603,-602.626627366114,-602,-601,-600,-599,-598,-597,-596,-595.118550948104,-595,-594,-593,-592,-591,-590,-589,-588,-587.803568676076,-587,-586,-585,-584,-583,-582,-581,-580.209317862512,-580,-579,-578,-577,-576,-575,-574,-573,-572.308209792819,-572,-571,-570,-569,-568,-567,-566,-565,-564.068369742204,-564,-563,-562,-561,-560,-559,-558,-557,-556.007765508745,-556,-555,-554,-553,-552,-551,-550,-549,-548.143731371079,-548,-547,-546,-545,-544,-543,-542,-541,-540,-539.967938515592,-539,-538,-537,-536,-535,-534,-533,-532,-531.442303824302,-531,-530,-529,-528,-527,-526,-525,-524,-523,-522.523340885777,-522,-521,-520,-519,-518,-517,-516,-515,-514,-513.643236970958,-513,-512,-511,-510,-509,-508,-507,-506,-505,-504.533891556040,-504,-503,-502,-501,-500,-499,-498,-497,-496,-495,-494.964535221343,-494,-493,-492,-491,-490,-489,-488,-487,-486,-485,-484.853141158356,-484,-483,-482,-481,-480,-479,-478,-477,-476,-475,-474.159609233154,-474,-473,-472,-471,-470,-469,-468,-467,-466,-465,-464,-463,-462,-461,-460,-459.829603818978,-459,-458,-457,-456,-455,-454,-453,-452,-451,-450,-449,-448,-447,-446,-445,-444,-443.702176542484,-443,-442,-441,-440,-439,-438,-437,-436,-435,-434,-433,-432,-431,-430,-429,-428,-427,-426,-425,-424,-423.566657156906,-423,-422,-421,-420,-419,-418,-417,-416,-415,-414,-413,-412,-411,-410,-409,-408,-407,-406,-405,-404,-403,-402,-401,-400,-399,-398,-397,-396,-395.761649028829,-395,-394,-393,-392,-391,-390,-389,-388,-387,-386,-385,-384,-383,-382,-381,-380,-379,-378,-377,-376,-375,-374,-373,-372,-371,-370,-369,-368,-367,-366,-365,-364,-363,-362,-361,-360,-359,-358,-357,-356,-355,-354,-353,-352,-351,-350,-349,-348,-347,-346,-345,-344,-343,-342,-341,-340,-339,-338,-337,-336,-335,-334,-333,-332,-331,-330,-329,-328,-327.263692482498,-327,-326,-325,-324,-323,-322,-321,-320,-319,-318,-317,-316,-315,-314,-313,-312,-311,-310,-309,-308,-307,-306,-305,-304,-303,-302.211440162754,-302,-301,-300,-299,-298,-297,-296,-295,-294,-293,-292,-291,-290,-289,-288,-287,-286,-285,-284.638895717488,-284,-283,-282,-281,-280,-279,-278,-277,-276,-275,-274,-273,-272,-271.404186459608,-271,-270,-269,-268,-267,-266,-265,-264,-263,-262,-261,-260.160036162189,-260,-259,-258,-257,-256,-255,-254,-253,-252.277941010226,-252,-251,-250,-249,-248,-247,-246,-245,-244.896048471425,-244,-243,-242,-241,-240,-239,-238.126075349081,-238,-237,-236,-235,-234,-233,-232.085260863913,-232,-231,-230,-229,-228,-227,-226.301055063302,-226,-225,-224,-223,-222,-221,-220.751893331387,-220,-219,-218,-217,-216,-215.419632841108,-215,-214,-213,-212,-211,-210.287784439696,-210,-209,-208,-207,-206,-205.342149178945,-205,-204,-203,-202,-201,-200.569828121763,-200,-199,-198,-197,-196.133250409093,-196,-195,-194,-193,-192,-191.850749868351,-191,-190,-189,-188,-187.689935576960,-187,-186,-185,-184,-183.644597707856,-183,-182,-181,-180,-179.709141707454,-179,-178,-177,-176,-175.878322955957,-175,-174,-173,-172.147457842199,-172,-171,-170,-169,-168.512023923535,-168,-167,-166,-165,-164.967462200158,-164,-163,-162,-161.510461076251,-161,-160,-159,-158.158839125700,-158,-157,-156,-155,-154.901021220631,-154,-153,-152,-151.715349213237,-151,-150,-149,-148.599118655049,-148,-147,-146,-145.549930239397,-145,-144,-143,-142.565490499690,-142,-141,-140,-139.643606062775,-139,-138,-137,-136.782178272456,-136,-135,-134,-133.979198155643,-133,-132,-131.233001755971,-131,-130,-129,-128.541564490815,-128,-127,-126,-125.903092445292,-125,-124,-123.316231902738,-123,-122,-121,-120.779162363189,-120,-119,-118.267241013918,-118,-117,-116,-115.792263881232,-115,-114,-113.363554036176,-113,-112,-111,-110.979638061369,-110,-109,-108.639623396632,-108,-107,-106.342007633343,-106,-105,-104.511325174957,-104,-103,-102.701102757189,-102,-101,-100.910966983676,-100,-99.1406851754976,-99,-98,-97.3898702207844,-97,-96,-95.6580941093722,-95,-94,-93.9450217044017,-93,-92.2505491431527,-92,-91,-90.5741958569446,-90,-89,-88.9156027468048,-88,-87.2747041123339,-87,-86,-85.6510514836192,-85,-84.0443221422085,-84,-83,-82.4545028647514,-82,-81,-80.8810243059266,-80,-79.3002840783002,-79,-78,-77.7057262209484,-77,-76.1280634918365,-76,-75,-74.5672022803333,-74,-73.0226141731160,-73,-72,-71.4944480252245,-71,-70,-69.9820366821993,-69,-68.4855888405308,-68,-67.0044413200715,-67,-66,-65.5388252787826,-65,-64.0881131589460,-64,-63,-62.6524292987996,-62,-61.2313394622665,-61,-60,-59.8247407282145,-59,-58.4324907039690,-58,-57.0542110907120,-57,-56,-55.6900004367522,-55,-54.3394549820734,-54,-53.0023642463761,-53,-52,-51.6788379704427,-51,-50.3684341359759,-50,-49.0709954661037,-49,-48,-47.7865444480214,-47,-46.5147999660455,-46,-45.2555555573051,-45,-44.1411214622480,-44,-43.0327713777981,-43,-42,-41.9305288647455,-41,-40.8343287493319,-40,-39.7306997003152,-39,-38.5897494278225,-38,-37.4555394942926,-37,-36.3280405186175,-36,-35.2072232982135,-35,-34.0930588076109,-34,-33,-32.9855349955581,-32,-31.8847056866424,-31,-30.7904338419718,-30,-29.7026913449017,-29,-28.6214502460078,-28,-27.5466827617971,-27,-26.4783612734323,-26,-25.4164583254666,-25,-24.3609466245922,-24,-23.3117990383997,-23,-22.2689885941494,-22,-21.2324884775544,-21,-20.2022720315748,-20,-19.1783127552239,-19,-18.1605843023849,-18,-17.1490604806390,-17,-16.1437152501048,-16,-15.1445227222876,-15,-14.1514571589406,-14,-13.1644929709357,-13,-12.1836047171456,-12,-11.2087671033355,-11,-10.2399549810656,-10,-9.27714334660377,-9,-8.32030733984743,-8,-7.36942224325670,-7,-6.42446348079622,-6,-5.48540661688698,-5,-4.55222735536815,-4,-3.62490153846785,-3,-2.72605648424666,-2,-1.83009110293136,-1,-0.937011811779161,-0.0468669840919462,0];
iq_cont = [116.494076075935,116.409875716636,116.327088615616,116.245683973714,116.165631898306,116.086903370297,116.009470212551,116,115.933313464155,115.858398583628,115.784698540306,115.712188264334,115.640843387887,115.570640220869,115.501555727607,115.433567504512,115.366653758638,115.300793287119,115.235965457426,115.172150188410,115.109327932106,115.047479656243,115,114.986587791354,114.926636407511,114.867604357188,114.809474526657,114.752230239490,114.695855242761,114.640333693785,114.585650147343,114.531789543381,114.478737195172,114.426478777907,114.375000317699,114.324288180996,114.274329064364,114.225109984648,114.176618269472,114.128841548087,114.081767742531,114.035385059107,114,113.989682087638,113.866181723916,113.744071802879,113.623332247276,113.503943378229,113.385885905477,113.269140917921,113.153689874430,113.039514594925,113,112.926596254082,112.814917369719,112.704461243972,112.595211071691,112.487150367454,112.380262958079,112.274532975348,112.169944848934,112.066483299522,112,111.964132037216,111.862874947568,111.762699835578,111.663592532793,111.565539129807,111.468525970452,111.372539646136,111.277566990342,111.183595073269,111.090611196614,111,110.998602805225,110.907552178997,110.817452487268,110.728291917539,110.640058864480,110.552741925482,110.466329896333,110.380811767000,110.296176717518,110.212414113990,110.129513504675,110.047464616193,110,109.966254448059,109.826047015755,109.687014967658,109.549146398674,109.412429575743,109.276852934820,109.142405077923,109.009074770234,109,108.876838400981,108.745696284532,108.615638573225,108.486654665279,108.358734108332,108.231866596889,108.106041969834,108,107.981248047704,107.857464742449,107.734694335880,107.612927227573,107.492153949612,107.372365164392,107.253551662461,107.135704360407,107.018814298788,107,106.902859822990,106.787842286390,106.673755543867,106.560591117979,106.448340645379,106.336995874984,106.226548666176,106.116990987037,106.008314912620,106,105.900497879001,105.793545444355,105.687451217328,105.582207689354,105.477807450581,105.374243188337,105.271507685618,105.169593819614,105.022550631693,105,104.876465921389,104.731348885417,104.587196202505,104.444000972039,104.301756370063,104.160455648297,104.020092133167,104,103.880638316687,103.742104806442,103.604488639560,103.467783436427,103.331982887456,103.197080752205,103.063070858515,103,102.929934040521,102.797665404047,102.666270639698,102.535743844157,102.406079178201,102.277270865917,102.149313193933,102.022200510648,102,101.895906500142,101.770441741831,101.645805154847,101.521991330976,101.398994920092,101.276810629457,101.155433223043,101.034857520859,101,100.915060420959,100.796047302372,100.677820477495,100.560374987262,100.443705925385,100.327808437735,100.212677721744,100.098309025806,100,99.9846942191488,99.8372575443485,99.6906429303792,99.5448462592270,99.3998634509650,99.2556904633999,99.1123232917234,99,98.9697508839920,98.8279500213617,98.6869429620720,98.5467258502155,98.4072948655609,98.2686462232300,98.1307761733795,98,97.9936794567974,97.8573219647507,97.7217318216821,97.5869054173678,97.4528391750596,97.3195295511900,97.1869730350818,97.0551661486612,97,96.9240860261759,96.7937344527875,96.6641220859689,96.5352455776615,96.4071016110044,96.2796869000691,96.1529981895977,96.0270322547437,96,95.9017596385155,95.7771960829291,95.6533456448199,95.5302052207056,95.4077717362489,95.2860421460183,95.1650134332520,95.0446826096247,95,94.9250258089850,94.8060484577719,94.6877600526713,94.5454978656495,94.4039399561804,94.2630840871395,94.1229280413112,94,93.9834648524880,93.8446616432353,93.7065515572213,93.5691324575308,93.4324022265891,93.2963587660542,93.1609999967114,93.0263238583687,93,92.8922960927962,92.7589388994038,92.6262581175630,92.4942517638759,92.3629178734542,92.2322544998234,92.1022597148266,92,91.9729232532408,91.8442200098359,91.7161795402011,91.5887999901968,91.4620795235354,91.3360163216932,91.2106085838244,91.0858545266752,91,90.9617401626019,90.8382485197191,90.7154051871974,90.5932084529467,90.4716566220534,90.3507480167013,90.2304809760954,90.1108538563859,90,89.9918623418988,89.8734709107170,89.7557144583457,89.6385914095647,89.5221002057301,89.3903924337233,89.2593056801869,89.1288389938861,89,88.9989910917101,88.8697174975760,88.7410610787961,88.6130209337398,88.4855961728059,88.3587859184057,88.2325893049481,88.1070054788237,88,87.9820272884490,87.8576226678232,87.7338282467679,87.6106432207769,87.4880667972588,87.3660981955262,87.2447366467841,87.1239813941204,87.0038316924958,87,86.8842448310365,86.7652605945614,86.6468796600654,86.5291013312498,86.4119249236507,86.2953497646333,86.1793751933870,86.0640005609202,86,85.9492062797988,85.8349867976459,85.7213653056691,85.6083412034791,85.4959139024943,85.3840828259393,85.2728474088455,85.1622070980509,85.0521613522018,85,84.9426875768107,84.8337872387557,84.7254798543088,84.6098143856285,84.4947184886374,84.3801921676724,84.2662354366424,84.1528483190558,84.0400308480492,84,83.9277544567617,83.8160319563672,83.7048792216557,83.5942963257833,83.4842833516893,83.3748403921273,83.2659675496974,83.1576649368784,83.0499326760611,83,82.9427476024028,82.8361128626864,82.7300488771824,82.6245558095631,82.5196338335934,82.4152831331671,82.3115039023440,82.2082963453875,82.1056606768026,82.0035971213749,82,81.9020648500131,81.8011036576340,81.7007153059491,81.6009000626559,81.5016582059437,81.4029900245362,81.3048958177345,81.2073758954608,81.1104305783024,81.0140601975574,81,80.9182297722516,80.8229689264237,80.7282840838313,80.6341756205817,80.5406439237375,80.4467354938603,80.3533757633722,80.2605655254184,80.1683055832425,80.0765967502480,80,79.9882407060095,79.9151063485446,79.8424885696442,79.7703869525120,79.6988010944308,79.6277306067711,79.5571751150020,79.4871342587023,79.4176076915733,79.3485950814519,79.2800961103254,79.2121104743471,79.1446378838527,79.0776780633783,79.0112307516790,79,78.9452737134101,78.8798242449726,78.8148866292551,78.7504606633343,78.6865461586248,78.6231429409043,78.5602508503404,78.4978697415179,78.4359994834678,78.3746399596977,78.3137910682219,78.2534527215944,78.1936248469421,78.1343073859990,78.0755002951424,78.0172035454292,78,77.9593999722346,77.9020995437822,77.8453095245969,77.7890299462680,77.7372729568405,77.6859984971773,77.6352069344599,77.5848986493161,77.5350740358852,77.4857335018823,77.4368774686659,77.3885063713051,77.3406206586487,77.2932207933950,77.2463072521638,77.1998805255681,77.1539411182888,77.1084895491487,77.0635263511897,77.0190520717497,77,76.9750561564325,76.9315419425552,76.8885184945732,76.8459864193028,76.8039463382802,76.7623988878475,76.7213447192394,76.6807844986718,76.6407189074319,76.6011486419694,76.5620744139889,76.5234969505448,76.4854169941361,76.4478353028045,76.4107526502323,76.3741698258431,76.3380876349034,76.3025068986258,76.2674284542741,76.2328531552698,76.1987818713001,76.1652154884277,76.1321549092023,76.0996010527737,76.0753131764837,76.0515040340002,76.0281748101363,76.0053267058852,76,75.9829527827609,75.9610600729840,75.9396523729799,75.9187309516023,75.8982970945770,75.8783521046418,75.8588973016884,75.8399340229054,75.8214636229244,75.8034874739671,75.7860069659947,75.7690235068599,75.7525385224599,75.7365534568926,75.7210697726139,75.7060889505980,75.6916124904992,75.6776419108164,75.6641787490597,75.6512245619191,75.6387809254353,75.6268494351740,75.6154317064008,75.6045293742600,75.5941440939552,75.5842775409320,75.5749314110642,75.5661074208416,75.5578073075610,75.5500328295193,75.5427857662099,75.5360679185210,75.5298811089375,75.5242271817448,75.5191080032362,75.5145254619226,75.5208870547442,75.5277588461992,75.5351429390964,75.5430414587925,75.5514565534207,75.5603903941232,75.5698451752857,75.5798231147763,75.5903264541870,75.6013574590781,75.6129184192270,75.6250116488794,75.6376394870048,75.6508042975544,75.6645084697241,75.6787544182193,75.6935445835252,75.7088814321791,75.7247674570482,75.7412051776095,75.7581971402351,75.7757459184805,75.7938541133774,75.8125243537305,75.8317592964183,75.8515616266983,75.8719340585164,75.8928793348207,75.9144002278799,75.9364995396057,75.9591801018803,75.9824447768884,76,76.0062930175964,76.0307212440699,76.0557419809984,76.0813582113831,76.1075729502081,76.1343892448012,76.1618101751996,76.1898388545214,76.2303297341377,76.2714042771987,76.3130657810940,76.3553175773962,76.3981630322598,76.4416055468277,76.4856485576426,76.5302955370641,76.5755499936929,76.6214154728003,76.6678955567644,76.7149938655132,76.7627140569729,76.8110598275245,76.8600349124659,76.9096430864814,76.9598881641181,77,77.0107679075107,77.0622692115188,77.1144186631457,77.1672202368757,77.2206779494866,77.2747958605694,77.3295780730563,77.3850287337567,77.4411520339015,77.4979522096950,77.5554335428764,77.6136003612891,77.6724570394585,77.7320079991796,77.7922577101130,77.8532106903904,77.9148715072293,77.9772447775577,78,78.0403118113286,78.1040870036512,78.1685882774574,78.2338204493272,78.2997883887419,78.3784856438589,78.4578974292131,78.5380287958964,78.6188848501375,78.7004707540276,78.7827917262584,78.8658530428720,78.9496600380223,79,79.0341980643590,79.1194626392656,79.2054887322184,79.2922819124501,79.3798478112293,79.4681921226986,79.5573206047264,79.6472390797718,79.7379534357651,79.8294696270018,79.9217936750514,80,80.0195861156951,80.1428356037552,80.2671736682936,80.3926075772315,80.5191446659261,80.6467923379527,80.7755580658966,80.9054493921569,81,81.0364522527532,81.1685391655878,81.3017740916273,81.4361648567912,81.5717193609675,81.7084455788859,81.8463515610042,81.9854454344066,82,82.1256608852175,82.2670714190421,82.4096940224113,82.5535371338629,82.6986092732114,82.8589060942777,83,83.0203889121491,83.1829944964601,83.3468148501691,83.5118586936230,83.6781348328415,83.8456521605706,84,84.0144112233970,84.1843386617790,84.3555340369666,84.5280065989193,84.7017656898470,84.8768207453620,85,85.0531504713000,85.2307233528340,85.4096206106937,85.5898520655242,85.7714276374177,85.9543573471740,86,86.1385717023513,86.3241338240974,86.5110802902034,86.6994215369715,86.8891681080359,87,87.0802849018141,87.2727647339945,87.4666817012705,87.6620467904236,87.8588711027241,88,88.0571335656272,88.2567974800659,88.4579541408667,88.6606151223393,88.8647921210224,89,89.0704574768433,89.2775862862751,89.4862664655463,89.6965102165906,89.9083298719520,90,90.1216703166872,90.3465739121863,90.5730321985384,90.8010577247358,91,91.0306463730773,91.2617183268164,91.4943959239360,91.7286922810452,91.9646206598904,92,92.2020854788576,92.4411900991374,92.6819673706442,92.9244311640242,93,93.1685058709140,93.4142549661958,93.6617331141932,93.9109548302363,94,94.1618499173213,94.4144712572036,94.6688807106711,94.9250934760936,95,95.1830303425305,95.4427626345212,95.7043449202947,95.9677931224082,96,96.2330047548369,96.5000983099312,96.7691067300283,97,97.0400265736581,97.3127784105891,97.5874958582095,97.8641962175383,98,98.1428263061109,98.4234071855298,98.7060242421582,98.9906956310439,99,99.2773047524003,99.5660007715987,99.8568070678724,100,100.149670799092,100.444614283982,100.745360875268,101,101.048201272770,101.353057676872,101.660070859953,101.969260903381,102,102.280519153516,102.593981866760,102.909684141897,103,103.227544651268,103.547647306814,103.870054755595,104,104.194703184785,104.521644055661,104.850957611554,105,105.182588058697,105.516573690376,105.853002698174,106,106.191818157777,106.533063805986,106.876826468482,107,107.223039320446,107.571769417213,107.923093270776,108,108.276925801948,108.633374452042,108.992496873312,109,109.354181834112,109.718593344219,110,110.085729251668,110.455543289220,110.828172732394,111,111.203570725224,111.581779456154,111.962893274346,112,112.346817049117,112.733694937792,113,113.123527862405,113.516297695344,113.912131679385,114,114.310955747202,114.707464209895,115,115.107013775085,115.509577494978,115.915287959530,116,116.324076521335,116.736056767767,117,117.151244942737,117.569644258506,117.991373766128,118,118.416348995270,118.844730083964,119,119.276480094397,119.711674835962,120,120.185901839155,120.731893216272,121,121.281267289844,121.834052853276,122,122.390281096364,122.949978233532,123,123.513183221486,124,124.079915709422,124.650220490899,125,125.224118128303,125.801646829566,126,126.382842126891,126.967723508014,127,127.556353143619,128,128.148733906712,128.744924369619,129,129.344950527066,129.948837022957,130,130.556656525471,131,131.168403998878,131.784146166463,132,132.403916176403,133,133.027727049969,133.655675368288,134,134.287749815639,134.923998930581,135,135.564505362727,136,136.187452535154,136.814596423065,137,137.445984037251,138,138.081618931305,138.721614339235,139,139.365971272641,140,140.014715757736,140.667987925866,141,141.325752045136,141.988056433120,142,142.655048326083,143,143.326683381662,144,144.003013612786,144.684201770218,145,145.370199149485,146,146.061060316647,146.756934613108,147,147.457815240513,148,148.163739065876,148.874818789863,149,149.591135188500,150,150.312685767035,151,151.039535507893,151.771856261731,152,152.509632368591,153,153.252915555670,154,154.001776962838,154.756413678952,155,155.516779953620,156,156.282951036526,157,157.055004873410,157.833114740950,158,158.617301194593,159,159.407617615539,160,160.228854232835,161,161.127037479915,162,162.029655505082,162.936818910967,163,163.848537438844,164,164.764828519750,165,165.639749746998,166,166.519228164065,167,167.403317077031,168,168.292070952566,169,169.185545445163,170,170.083797425187,170.986900286099,171,171.894991793892,172,172.808036115695,173,173.726094992063,174,174.649231524360,175,175.577510208070,176,176.510996967141,177,177.449759189414,178,178.393865763149,179,179.343387114714,180,180.298395247458,181,181.258963781833,182,182.225167996785,183,183.197084872483,184,184.174793134426,185,185.158373298978,186,186.147907720386,187,187.143480639345,188,188.145178233150,189,189.153088667517,190,190.167302150123,191,191.187910985932,192,192.215009634389,193,193.248694768531,194,194.289065336122,195,195.336222622857,196,196.390270317749,197,197.451314580760,198,198.519464112790,199,199.594830228095,200,200.694988177277,201,201.810189282605,202,202.929397197108,203,204,204.052770228964];
id_long = linspace(-800,0,8000);
%% calc
iq_long = fittingcurve(id_cont, iq_cont,id_long);
figure;hold on;
plot(id_cont,iq_cont, '+')
plot(id_long,iq_long,'*')
legend('orig data','fitted curve')
%% 2-D Curve fitting
function output_fit = fittingcurve(x_values, y_values, x_data)
[xData, yData] = prepareCurveData( x_values, y_values);
% Set up fittype and options.
ft = fittype( 'poly9' );
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, 'Normalize', 'on' );
y_coeffvals = coeffvalues(fitresult);
x_mean = mean(x_data(1,:));
x_std = std(x_data(1,:));
output_fit = y_coeffvals(1).*((x_data-x_mean)./x_std).^9 ...
+ y_coeffvals(2).*((x_data-x_mean)./x_std).^8 ...
+ y_coeffvals(3).*((x_data-x_mean)./x_std).^7 ...
+ y_coeffvals(4).*((x_data-x_mean)./x_std).^6 ...
+ y_coeffvals(5).*((x_data-x_mean)./x_std).^5 ...
+ y_coeffvals(6).*((x_data-x_mean)./x_std).^4 ...
+ y_coeffvals(7).*((x_data-x_mean)./x_std).^3 ...
+ y_coeffvals(8).*((x_data-x_mean)./x_std).^2 ...
+ y_coeffvals(9).*((x_data-x_mean)./x_std) ...
+ y_coeffvals(10);
end
Produces the following plot
untitled.png

Best Answer

Sorted it (Mostly)
needed to calculate mean and stadard deviation of the original data not the new data to normalize.
x_mean = mean(x_values(1,:));
x_std = std(x_values(1,:));
Correcting these two lines produces the following result
untitled.png