{"id":472,"date":"2010-09-13T08:00:07","date_gmt":"2010-09-13T08:00:07","guid":{"rendered":"https:\/\/blogs.mathworks.com\/videos\/2010\/09\/13\/unexpected-is-not-wrong\/"},"modified":"2010-09-02T18:07:34","modified_gmt":"2010-09-02T18:07:34","slug":"unexpected-is-not-wrong","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/videos\/2010\/09\/13\/unexpected-is-not-wrong\/","title":{"rendered":"Unexpected is not wrong"},"content":{"rendered":"I just worked on a case that typifies a situation I see in MATLAB fairly often.\r\n\r\nUnexpected results are not necessarily wrong results.  I am a big fan of the &#8220;sanity check&#8221;, where if the results just seem &#8220;way out there&#8221; logically, something might be wrong.\r\n\r\n<ul>\r\n\r\n\t<li>It could be the MATLAB code you wrote<\/li>\r\n\r\n        <li>It could be the MATLAB code you got from someone else<\/li>\r\n\r\n\t<li>It could be your data<\/li>\r\n\r\n\t<li>It could be the MATLAB code we wrote<\/li>\r\n\r\n<\/ul>\r\n\r\nBeing in technical support, I see a lot of the cases where MATLAB users <em>think<\/em> it is the last of these items.  If it is, we own up to it and fix it.  However, there is an army of people here at MathWorks running countless tests to ensure accuracy and stability of our code base.  It is exceedingly rare for incorrect algorithms to sneak into the code.\r\n\r\nToday&#8217;s case was one where a MATLAB user doing an isosurface over a volume of data where the volume represented the distance from the origin.  Any isosurfaces will simply be spheres.  This makes sense.  What did not make sense was there was a second much smaller sphere inside the first sphere.  Here is a plot of all the vertices of the isosurface.  Notice the points in red which form a secondary inner sphere.\r\n\r\n<img src='https:\/\/blogs.mathworks.com\/videos\/..\/images\/videos\/2010\/08\/innersphere.jpg' alt='innersphere.jpg' \/>\r\n<p>\r\nThis was distressing, I looked through the code for a long time until I noticed in the workspace browser:\r\n<p>\r\n<img src='https:\/\/blogs.mathworks.com\/videos\/..\/images\/videos\/2010\/08\/outlier.jpg' alt='outlier.jpg' \/>\r\n<p>\r\nIt turns out that there was one data point in the middle of the sphere with a very high value.  So, due to the interpolation that MATLAB is supposed to do for isosurface, there <strong>must <\/strong>be a sphere in the inside too because there will be a sharp gradient from this high outlier to the low values surrounding it.\r\n<p>\r\nMATLAB was doing exactly what it was supposed to do.  \r\n<p>\r\nI never found out if that outlier was important.  The right answer might be to NaN out that outlier and carry on with the expected results, or it that &#8216;extra&#8217; isosurface might point to something important that would have been otherwise missed.\r\n<p>\r\nHave you had MATLAB give unexpected results, only to find out that there was something unexpected in your data?","protected":false},"excerpt":{"rendered":"<p>I just worked on a case that typifies a situation I see in MATLAB fairly often.\r\n\r\nUnexpected results are not necessarily wrong results.  I am a big fan of the &#8220;sanity check&#8221;, where if&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/videos\/2010\/09\/13\/unexpected-is-not-wrong\/\">read more >><\/a><\/p>","protected":false},"author":68,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,25],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/472"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/comments?post=472"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/472\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/media?parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/categories?post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/tags?post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}