Interpolation when y data is not strictly a function of x

6 views (last 30 days)
Lets suppose I have the following two sets of data, where y is a not a proper function of x:
x1 = [-200,-195,-190,-185,-180,-175,-170,-165,-160,-155,-150,-145,-140,-135,-130,-125,-120,-115,-110,-105,-100,-98.75,-97.5,-96.25,-95,-93.75,-92.5,-91.25,-90,-88.75,-87.5,-86.25,-85,-83.75,-82.5,-81.25,-80,-78.75,-77.5,-76.25,-75,-73.75,-72.5,-71.25,-70,-68.75,-67.5,-66.25,-65,-63.75,-62.5,-61.25,-60,-58.75,-57.5,-56.25,-55,-53.75,-52.5,-51.25,-50,-48.75,-47.5,-46.25,-45,-43.75,-42.5,-41.25,-40,-38.75,-37.5,-36.25,-35,-33.75,-32.5,-31.25,-30,-28.75,-27.5,-26.25,-25,-23.75,-22.5,-21.25,-20,-18.75,-17.5,-16.25,-15,-13.75,-12.5,-11.25,-10,-8.75,-7.5,-6.25,-5,-3.75,-2.5,-1.25,0,1.25,2.5,3.75,5,6.25,7.5,8.75,10,11.25,12.5,13.75,15,16.25,17.5,18.75,20,21.25,22.5,23.75,25,26.25,27.5,28.75,30,31.25,32.5,33.75,35,36.25,37.5,38.75,40,41.25,42.5,43.75,45,46.25,47.5,48.75,50,51.25,52.5,53.75,55,56.25,57.5,58.75,60,61.25,62.5,63.75,65,66.25,67.5,68.75,70,71.25,72.5,73.75,75,76.25,77.5,78.75,80,81.25,82.5,83.75,85,86.25,87.5,88.75,90,91.25,92.5,93.75,95,96.25,97.5,98.75,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,200,195,190,185,180,175,170,165,160,155,150,145,140,135,130,125,120,115,110,105,100,98.75,97.5,96.25,95,93.75,92.5,91.25,90,88.75,87.5,86.25,85,83.75,82.5,81.25,80,78.75,77.5,76.25,75,73.75,72.5,71.25,70,68.75,67.5,66.25,65,63.75,62.5,61.25,60,58.75,57.5,56.25,55,53.75,52.5,51.25,50,48.75,47.5,46.25,45,43.75,42.5,41.25,40,38.75,37.5,36.25,35,33.75,32.5,31.25,30,28.75,27.5,26.25,25,23.75,22.5,21.25,20,18.75,17.5,16.25,15,13.75,12.5,11.25,10,8.75,7.5,6.25,5,3.75,2.5,1.25,0,-1.25,-2.5,-3.75,-5,-6.25,-7.5,-8.75,-10,-11.25,-12.5,-13.75,-15,-16.25,-17.5,-18.75,-20,-21.25,-22.5,-23.75,-25,-26.25,-27.5,-28.75,-30,-31.25,-32.5,-33.75,-35,-36.25,-37.5,-38.75,-40,-41.25,-42.5,-43.75,-45,-46.25,-47.5,-48.75,-50,-51.25,-52.5,-53.75,-55,-56.25,-57.5,-58.75,-60,-61.25,-62.5,-63.75,-65,-66.25,-67.5,-68.75,-70,-71.25,-72.5,-73.75,-75,-76.25,-77.5,-78.75,-80,-81.25,-82.5,-83.75,-85,-86.25,-87.5,-88.75,-90,-91.25,-92.5,-93.75,-95,-96.25,-97.5,-98.75,-100,-105,-110,-115,-120,-125,-130,-135,-140,-145,-150,-155,-160,-165,-170,-175,-180,-185,-190,-195,-200];
y1 = [-0.998164595,-0.998078365,-0.997986113,-0.997887339,-0.997781497,-0.997667995,-0.997546191,-0.997415382,-0.997274804,-0.997123618,-0.996960906,-0.996785654,-0.996596749,-0.996392948,-0.996172861,-0.995934932,-0.9956774,-0.99539826,-0.99509522,-0.994765636,-0.994406441,-0.994311705,-0.994214737,-0.99411558,-0.994014157,-0.993910397,-0.993804234,-0.993695584,-0.993584373,-0.993470516,-0.993353924,-0.993234501,-0.993112141,-0.992986783,-0.992858315,-0.992726605,-0.992591565,-0.992453059,-0.992310959,-0.99216513,-0.99190296,-0.9917469,-0.991586658,-0.991422063,-0.991252944,-0.991079118,-0.990900393,-0.990716565,-0.990527421,-0.990332733,-0.990132259,-0.989925745,-0.989712921,-0.989493497,-0.989267171,-0.989033615,-0.988792483,-0.988543405,-0.988285987,-0.988019807,-0.987744414,-0.987459322,-0.987164013,-0.986857927,-0.986540465,-0.986210976,-0.985868761,-0.985513058,-0.985143054,-0.984757846,-0.984356469,-0.983937869,-0.983500875,-0.983044211,-0.982566505,-0.982066184,-0.98154156,-0.980990653,-0.980411354,-0.979801307,-0.979157756,-0.978477618,-0.977757243,-0.976992368,-0.976177837,-0.975307221,-0.97437204,-0.973360408,-0.97225378,-0.9710193,-0.969586882,-0.967751822,-0.96504007,-0.961099005,-0.95486125,-0.942362109,-0.918761451,-0.891813695,-0.730557262,-0.670544475,-0.608495977,-0.544449362,-0.478272201,-0.409966632,-0.339177458,-0.265166123,0.414538615,0.479074024,0.533638997,0.5842766,0.620066944,0.658075109,0.690081822,0.721732218,0.748082282,0.777318797,0.798508123,0.870643811,0.878835187,0.891094754,0.900880759,0.907494578,0.914513834,0.92288014,0.928661143,0.981759598,0.982282358,0.982782685,0.983263306,0.983731727,0.984356368,0.984757709,0.985142934,0.985512957,0.985868672,0.986210898,0.986540397,0.986857866,0.987163956,0.987459268,0.987744362,0.988019756,0.988285937,0.988543354,0.988792432,0.989033564,0.989267121,0.989493446,0.98971287,0.989925694,0.99013221,0.990332683,0.990527374,0.99071652,0.990900347,0.991079074,0.991252901,0.991422022,0.991586618,0.991746861,0.991902916,0.99205494,0.992203077,0.992347471,0.992488255,0.992625555,0.992759494,0.992890186,0.993017741,0.993142267,0.993263863,0.993382625,0.993498643,0.993612009,0.993722803,0.993831109,0.993936999,0.994040552,0.994141838,0.994240923,0.994337871,0.994705532,0.99504362,0.995355254,0.995643117,0.995909537,0.996156539,0.996385879,0.99659673,0.996785649,0.996960904,0.997123613,0.997274797,0.997415377,0.997546184,0.99766799,0.997781493,0.997887335,0.997986111,0.998078364,0.998164596,0.998164595,0.998078365,0.997986113,0.997887339,0.997781497,0.997667995,0.997546191,0.997415382,0.997274804,0.997123618,0.996960906,0.996785654,0.996596749,0.996392948,0.996172861,0.995934932,0.9956774,0.99539826,0.99509522,0.994765636,0.994406441,0.994311705,0.994214737,0.99411558,0.994014157,0.993910397,0.993804234,0.993695584,0.993584373,0.993470516,0.993353924,0.993234501,0.993112141,0.992986783,0.992858315,0.992726605,0.992591565,0.992453059,0.992310959,0.99216513,0.99190296,0.9917469,0.991586658,0.991422063,0.991252944,0.991079118,0.990900393,0.990716565,0.990527421,0.990332733,0.990132259,0.989925745,0.989712921,0.989493497,0.989267171,0.989033615,0.988792483,0.988543405,0.988285987,0.988019807,0.987744414,0.987459322,0.987164013,0.986857927,0.986540465,0.986210976,0.985868761,0.985513058,0.985143054,0.984757846,0.984356469,0.983937869,0.983500875,0.983044211,0.982566505,0.982066184,0.98154156,0.980990653,0.980411354,0.979801307,0.979157756,0.978477618,0.977757243,0.976992368,0.976177837,0.975307221,0.97437204,0.973360408,0.97225378,0.9710193,0.969586882,0.967751822,0.96504007,0.961099005,0.95486125,0.942362109,0.918761451,0.891813695,0.730557262,0.670544475,0.608495977,0.544449362,0.478272201,0.409966632,0.339177458,0.265166123,-0.414538615,-0.479074024,-0.533638997,-0.5842766,-0.620066944,-0.658075109,-0.690081822,-0.721732218,-0.748082282,-0.777318797,-0.798508123,-0.870643811,-0.878835187,-0.891094754,-0.900880759,-0.907494578,-0.914513834,-0.92288014,-0.928661143,-0.981759598,-0.982282358,-0.982782685,-0.983263306,-0.983731727,-0.984356368,-0.984757709,-0.985142934,-0.985512957,-0.985868672,-0.986210898,-0.986540397,-0.986857866,-0.987163956,-0.987459268,-0.987744362,-0.988019756,-0.988285937,-0.988543354,-0.988792432,-0.989033564,-0.989267121,-0.989493446,-0.98971287,-0.989925694,-0.99013221,-0.990332683,-0.990527374,-0.99071652,-0.990900347,-0.991079074,-0.991252901,-0.991422022,-0.991586618,-0.991746861,-0.991902916,-0.99205494,-0.992203077,-0.992347471,-0.992488255,-0.992625555,-0.992759494,-0.992890186,-0.993017741,-0.993142267,-0.993263863,-0.993382625,-0.993498643,-0.993612009,-0.993722803,-0.993831109,-0.993936999,-0.994040552,-0.994141838,-0.994240923,-0.994337871,-0.994705532,-0.99504362,-0.995355254,-0.995643117,-0.995909537,-0.996156539,-0.996385879,-0.99659673,-0.996785649,-0.996960904,-0.997123613,-0.997274797,-0.997415377,-0.997546184,-0.99766799,-0.997781493,-0.997887335,-0.997986111,-0.998078364,-0.998164596];
x2 = [200,197.5,195,192.5,190,187.5,185,182.5,180,177.5,175,172.5,170,167.5,165,162.5,160,157.5,155,152.5,150,147.5,145,142.5,140,137.5,135,132.5,130,127.5,125,122.5,120,117.5,115,112.5,110,107.5,105,102.5,100,50,49.28571429,48.57142857,47.85714286,47.14285714,46.42857143,45.71428571,45,44.28571429,43.57142857,42.85714286,42.14285714,41.42857143,40.71428571,40,39.28571429,38.57142857,37.85714286,37.14285714,36.42857143,35.71428571,35,34.28571429,33.57142857,32.85714286,32.14285714,31.42857143,30.71428571,30,29.28571429,28.57142857,27.85714286,27.14285714,26.42857143,25.71428571,25,24.28571429,23.57142857,22.85714286,22.14285714,21.42857143,20.71428571,20,19.28571429,18.57142857,17.85714286,17.14285714,16.42857143,15.71428571,15,14.28571429,13.57142857,12.85714286,12.14285714,11.42857143,10.71428571,10,9.285714286,8.571428571,7.857142857,7.142857143,6.428571429,5.714285714,5,4.285714286,3.571428571,2.857142857,2.142857143,1.428571429,0.714285714,0,-0.714285714,-1.428571429,-2.142857143,-2.857142857,-3.571428571,-4.285714286,-5,-5.714285714,-6.428571429,-7.142857143,-7.857142857,-8.571428571,-9.285714286,-10,-10.71428571,-11.42857143,-12.14285714,-12.85714286,-13.57142857,-14.28571429,-15,-15.71428571,-16.42857143,-17.14285714,-17.85714286,-18.57142857,-19.28571429,-20,-20.71428571,-21.42857143,-22.14285714,-22.85714286,-23.57142857,-24.28571429,-25,-25.71428571,-26.42857143,-27.14285714,-27.85714286,-28.57142857,-29.28571429,-30,-30.71428571,-31.42857143,-32.14285714,-32.85714286,-33.57142857,-34.28571429,-35,-35.71428571,-36.42857143,-37.14285714,-37.85714286,-38.57142857,-39.28571429,-40,-40.71428571,-41.42857143,-42.14285714,-42.85714286,-43.57142857,-44.28571429,-45,-45.71428571,-46.42857143,-47.14285714,-47.85714286,-48.57142857,-49.28571429,-50,-53.75,-57.5,-61.25,-65,-68.75,-72.5,-76.25,-80,-83.75,-87.5,-91.25,-95,-98.75,-102.5,-106.25,-110,-113.75,-117.5,-121.25,-125,-128.75,-132.5,-136.25,-140,-143.75,-147.5,-151.25,-155,-158.75,-162.5,-166.25,-170,-173.75,-177.5,-181.25,-185,-188.75,-192.5,-196.25,-200,-197.5,-195,-192.5,-190,-187.5,-185,-182.5,-180,-177.5,-175,-172.5,-170,-167.5,-165,-162.5,-160,-157.5,-155,-152.5,-150,-147.5,-145,-142.5,-140,-137.5,-135,-132.5,-130,-127.5,-125,-122.5,-120,-117.5,-115,-112.5,-110,-107.5,-105,-102.5,-100,-50,-49.28571429,-48.57142857,-47.85714286,-47.14285714,-46.42857143,-45.71428571,-45,-44.28571429,-43.57142857,-42.85714286,-42.14285714,-41.42857143,-40.71428571,-40,-39.28571429,-38.57142857,-37.85714286,-37.14285714,-36.42857143,-35.71428571,-35,-34.28571429,-33.57142857,-32.85714286,-32.14285714,-31.42857143,-30.71428571,-30,-29.28571429,-28.57142857,-27.85714286,-27.14285714,-26.42857143,-25.71428571,-25,-24.28571429,-23.57142857,-22.85714286,-22.14285714,-21.42857143,-20.71428571,-20,-19.28571429,-18.57142857,-17.85714286,-17.14285714,-16.42857143,-15.71428571,-15,-14.28571429,-13.57142857,-12.85714286,-12.14285714,-11.42857143,-10.71428571,-10,-9.285714286,-8.571428571,-7.857142857,-7.142857143,-6.428571429,-5.714285714,-5,-4.285714286,-3.571428571,-2.857142857,-2.142857143,-1.428571429,-0.714285714,0,0.714285714,1.428571429,2.142857143,2.857142857,3.571428571,4.285714286,5,5.714285714,6.428571429,7.142857143,7.857142857,8.571428571,9.285714286,10,10.71428571,11.42857143,12.14285714,12.85714286,13.57142857,14.28571429,15,15.71428571,16.42857143,17.14285714,17.85714286,18.57142857,19.28571429,20,20.71428571,21.42857143,22.14285714,22.85714286,23.57142857,24.28571429,25,25.71428571,26.42857143,27.14285714,27.85714286,28.57142857,29.28571429,30,30.71428571,31.42857143,32.14285714,32.85714286,33.57142857,34.28571429,35,35.71428571,36.42857143,37.14285714,37.85714286,38.57142857,39.28571429,40,40.71428571,41.42857143,42.14285714,42.85714286,43.57142857,44.28571429,45,45.71428571,46.42857143,47.14285714,47.85714286,48.57142857,49.28571429,50,53.75,57.5,61.25,65,68.75,72.5,76.25,80,83.75,87.5,91.25,95,98.75,102.5,106.25,110,113.75,117.5,121.25,125,128.75,132.5,136.25,140,143.75,147.5,151.25,155,158.75,162.5,166.25,170,173.75,177.5,181.25,185,188.75,192.5,196.25,20-];
y2 = [0.997146363,0.99708675,0.997025361,0.996962134,0.996897004,0.996829904,0.996760766,0.996689516,0.996616079,0.996540377,0.996462326,0.996381842,0.996298836,0.996213214,0.996124878,0.996033726,0.995939649,0.995842538,0.995742273,0.995638729,0.995531778,0.995421281,0.995307095,0.995189066,0.995067033,0.994940826,0.994810266,0.994675161,0.994535309,0.994390494,0.994240491,0.994085054,0.993923926,0.993756831,0.993583474,0.99340354,0.993216693,0.993022572,0.992731781,0.992517773,0.992295203,0.984838992,0.984663413,0.984484496,0.984302226,0.984116507,0.983927237,0.983734306,0.983537599,0.983336983,0.983132341,0.982923526,0.98271042,0.982492851,0.982270671,0.982043702,0.981811767,0.981574654,0.981332181,0.981084091,0.980830152,0.980570071,0.980303566,0.980030289,0.979749857,0.979461845,0.979165745,0.97886099,0.978546882,0.978222598,0.977887159,0.97753931,0.977177546,0.976799966,0.976404246,0.975987524,0.975546431,0.975077197,0.974575598,0.974037122,0.97345635,0.972827384,0.972144151,0.971399509,0.97058671,0.969698626,0.968727494,0.96766162,0.966482429,0.965160634,0.963655517,0.961921782,0.959916204,0.957571092,0.954701078,0.950902769,0.945879628,0.939786039,0.932788555,0.922068417,0.879552425,0.861986051,0.844707961,0.827076942,0.808916164,0.783376445,0.760860309,0.738601393,0.696489554,0.561909966,0.06598797,0.008646147,-0.047904486,-0.091419305,-0.128018286,-0.165218319,-0.195875322,-0.226573705,-0.249872295,-0.290316146,-0.312049377,-0.335098655,-0.375971146,-0.398221925,-0.429215406,-0.451017313,-0.47271821,-0.502919473,-0.749931153,-0.781972439,-0.809132394,-0.820311643,-0.833036737,-0.845148011,-0.887040911,-0.894259084,-0.898348184,-0.90449425,-0.910835452,-0.915962824,-0.918640837,-0.923153948,-0.925590813,-0.93168999,-0.940176579,-0.941797032,-0.94483286,-0.967948246,-0.968642973,-0.969332265,-0.973445746,-0.973939863,-0.974415163,-0.974872362,-0.975312559,-0.975737149,-0.976147535,-0.976545136,-0.97693126,-0.977307241,-0.977674557,-0.978034995,-0.978391451,-0.978751444,-0.980482889,-0.980758424,-0.981029683,-0.981298828,-0.981579942,-0.982127018,-0.982356723,-0.98258198,-0.982802684,-0.983019037,-0.983231226,-0.983439443,-0.983643897,-0.983844811,-0.984042476,-0.984237277,-0.984429903,-0.984622323,-0.985711384,-0.986508047,-0.987238678,-0.987911105,-0.988532003,-0.989107017,-0.989640961,-0.990138,-0.99060172,-0.991035255,-0.991441355,-0.991822436,-0.992180618,-0.992517816,-0.992835702,-0.9931358,-0.993419465,-0.993687916,-0.993942245,-0.994183443,-0.994412413,-0.994629974,-0.994836872,-0.995033792,-0.995221352,-0.995400127,-0.995570641,-0.99573337,-0.995888723,-0.996033719,-0.996169389,-0.99629884,-0.996422396,-0.996540379,-0.996653078,-0.996760768,-0.996863707,-0.996962137,-0.997056285,-0.997146363,-0.99708675,-0.997025361,-0.996962134,-0.996897004,-0.996829904,-0.996760766,-0.996689516,-0.996616079,-0.996540377,-0.996462326,-0.996381842,-0.996298836,-0.996213214,-0.996124878,-0.996033726,-0.995939649,-0.995842538,-0.995742273,-0.995638729,-0.995531778,-0.995421281,-0.995307095,-0.995189066,-0.995067033,-0.994940826,-0.994810266,-0.994675161,-0.994535309,-0.994390494,-0.994240491,-0.994085054,-0.993923926,-0.993756831,-0.993583474,-0.99340354,-0.993216693,-0.993022572,-0.992731781,-0.992517773,-0.992295203,-0.984838992,-0.984663413,-0.984484496,-0.984302226,-0.984116507,-0.983927237,-0.983734306,-0.983537599,-0.983336983,-0.983132341,-0.982923526,-0.98271042,-0.982492851,-0.982270671,-0.982043702,-0.981811767,-0.981574654,-0.981332181,-0.981084091,-0.980830152,-0.980570071,-0.980303566,-0.980030289,-0.979749857,-0.979461845,-0.979165745,-0.97886099,-0.978546882,-0.978222598,-0.977887159,-0.97753931,-0.977177546,-0.976799966,-0.976404246,-0.975987524,-0.975546431,-0.975077197,-0.974575598,-0.974037122,-0.97345635,-0.972827384,-0.972144151,-0.971399509,-0.97058671,-0.969698626,-0.968727494,-0.96766162,-0.966482429,-0.965160634,-0.963655517,-0.961921782,-0.959916204,-0.957571092,-0.954701078,-0.950902769,-0.945879628,-0.939786039,-0.932788555,-0.922068417,-0.879552425,-0.861986051,-0.844707961,-0.827076942,-0.808916164,-0.783376445,-0.760860309,-0.738601393,-0.696489554,-0.561909966,-0.06598797,-0.008646147,0.047904486,0.091419305,0.128018286,0.165218319,0.195875322,0.226573705,0.249872295,0.290316146,0.312049377,0.335098655,0.375971146,0.398221925,0.429215406,0.451017313,0.47271821,0.502919473,0.749931153,0.781972439,0.809132394,0.820311643,0.833036737,0.845148011,0.887040911,0.894259084,0.898348184,0.90449425,0.910835452,0.915962824,0.918640837,0.923153948,0.925590813,0.93168999,0.940176579,0.941797032,0.94483286,0.967948246,0.968642973,0.969332265,0.973445746,0.973939863,0.974415163,0.974872362,0.975312559,0.975737149,0.976147535,0.976545136,0.97693126,0.977307241,0.977674557,0.978034995,0.978391451,0.978751444,0.980482889,0.980758424,0.981029683,0.981298828,0.981579942,0.982127018,0.982356723,0.98258198,0.982802684,0.983019037,0.983231226,0.983439443,0.983643897,0.983844811,0.984042476,0.984237277,0.984429903,0.984622323,0.985711384,0.986508047,0.987238678,0.987911105,0.988532003,0.989107017,0.989640961,0.990138,0.99060172,0.991035255,0.991441355,0.991822436,0.992180618,0.992517816,0.992835702,0.9931358,0.993419465,0.993687916,0.993942245,0.994183443,0.994412413,0.994629974,0.994836872,0.995033792,0.995221352,0.995400127,0.995570641,0.99573337,0.995888723,0.996033719,0.996169389,0.99629884,0.996422396,0.996540379,0.996653078,0.996760768,0.996863707,0.996962137,0.997056285,0.997146367];
Which when plotted looks like:
and
You may have noticed that the vectors x1 and y1 are not of the same length as x2 and y2, and the step size in the y's is not consistant.
I would like to add a*x1 to b* x2 and map them onto the same y values, where a and b are constants. Since x1 and x2 are not of the same length, simply adding them does not work. I've attempted to use interpolation in the following:
x2New = interp1(x2, y2, x1);
However I get the following error:
The grid vectors must contain unique points.
Could someone please help me out on how I could achive adding x1 to x2?
  3 Comments
dpb
dpb on 22 Jun 2019
Edited: dpb on 22 Jun 2019
That is a typo that should be 200, Walter, by symmetry.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 22 Jun 2019
I am not certain what you want to do.
Your data appear to be hysteresis curves. It is straightforward to fit them, using my Answer in how to find ascending and descending of hysteresis loop?
A slightly updated version of that code for your data is:
x = x1;
y = y1;
[cmin,cxix] = (min(x))
[cmax,cnix] = (max(x))
[fmin,fxix] = (min(y))
[fmax,fnix] = (max(y))
figure(1)
plot(x, y)
hold on
plot([cmin cmax], [fmin fmax], '+r', 'MarkerSize', 5, 'LineWidth',1.5)
hold off
grid
text(cmin,fmin, sprintf('(%.3f, %.3f)',cmin, fmin), 'FontSize',8, 'FontName', 'Consolas', 'FontWeight', 'bold', 'VerticalAlignment','bottom', 'HorizontalAlignment','left')
text(cmax,fmax, sprintf('(%.3f, %.3f)',cmax, fmax), 'FontSize',8, 'FontName', 'Consolas', 'FontWeight', 'bold', 'VerticalAlignment','top', 'HorizontalAlignment','right')
xlabel('Current')
ylabel('Flux')
Phi1 = @(b,I) -(b(1) .* atan(-b(2)*I+b(3)) - b(1).*I.*b(4)); % Descending
Phi2 = @(b,I) (b(1) .* atan(-b(2)*I+b(3)) + b(1).*I.*b(4)); % Ascending
ixd = fix(length(x)/2);
vi2 = 1:ixd;
vi1 = ixd:length(x);
opts = statset('MaxIter', 5000, 'MaxFunEvals', 10000);
B1 = nlinfit(x(vi1), y(vi1), Phi1, ones(4,1), opts )
B2 = nlinfit(x(vi2), y(vi2), Phi2, ones(4,1), opts )
FitPhi1 = Phi1(B1,x);
FitPhi2 = Phi2(B2,x);
figure(2)
hpd1 = plot(x(vi1), y(vi1), '.b', x(vi2), y(vi2), '.b', 'LineWidth',1);
hold on
hpr1 = plot(x, FitPhi1, '-r', 'LineWidth', 1.5);
hpr2 = plot(x, FitPhi2, '-g', 'LineWidth', 1.5);
hold off
grid
legend([hpd1(1),hpr1,hpr2], 'Data', 'Descending', 'Ascending', 'Location', 'NW')
xlabel('x_1')
ylabel('y_1')
Do the same for ‘x2’ and ‘y2’, once you have corrected ‘x2’. Remember to save both ‘B1’ and ‘B2’ for (x1,y1) and (x2,y2) separately, if you want to use them later. It is likely easiest to save them in one or two .mat files.
These are model fits. They are not interpolations. They will produce fitted estimates, not your original data. However, you can define whatever ‘x’ values you want and use them in:
FitPhi1 = Phi1(B1,x);
FitPhi2 = Phi2(B2,x);
to get the appropriate curves for both sets of variables, corresponding to the estimated parameters.
  2 Comments
Kilian Liss
Kilian Liss on 23 Jun 2019
Yes you are right, these are indeed hysteresis curves. These ones in particular are obtained by simulations representative of my sample (2 micrometer sized permalloy cylinders, about 20-30 nm thick, with the aim of studying magnetic vortices). The issue is since our array of cylinders contains defects and occassionally vary in diameter, I'll run various simulation, each representative of a different section of the sample, and add the simulated data proportionally to my actual sample. The goal is to understand what magnetic state the permalloy cylinders are in.
Thanks heaps for helping out, and I didn't think i'd be able to fit the data eitehr.

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!