{"id":512,"date":"2012-04-03T07:00:28","date_gmt":"2012-04-03T11:00:28","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=512"},"modified":"2019-10-31T14:45:13","modified_gmt":"2019-10-31T18:45:13","slug":"matlab-r2012a","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2012\/04\/03\/matlab-r2012a\/","title":{"rendered":"MATLAB R2012a"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p>Some of my fellow <a href=\"https:\/\/blogs.mathworks.com\">MATLAB Central bloggers<\/a> have already talked about the MATLAB R2012a release. Usually, I like to scan the release notes and pick out just a few things\r\n      that particularly interest me. I encourage you to take a look at the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/techdoc\/rn\/rn_intro.html\">release notes<\/a> to see what else is there that might interest you.\r\n   <\/p>\r\n   <p>I was particularly happy to see that the web browser system built into MATLAB (used for various purposes, including the help\r\n      system and the publish feature) was completely overhauled so that it looks a lot better on 64-bit Windows systems.\r\n   <\/p>\r\n   <p>Speaking of the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/techdoc\/matlab_env\/f6-22451.html\">publish<\/a> feature, have you heard of it? It's a great way to turn a MATLAB script (or function) into a web page, or a PDF, or a Word\r\n      document. I use it to create almost all of my blog posts. You can find a lot of examples online by searching for the phrase\r\n      \"Published with MATLAB\", such as <a href=\"http:\/\/www2.math.umd.edu\/~jmr\/241\/calc.html\">Calculus with MATLAB<\/a>. Anyway, you can include syntax-highlighted code in your published output. For example:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">bw = imread(<span style=\"color: #A020F0\">'text.png'<\/span>);\r\ns = regionprops(bw, {<span style=\"color: #A020F0\">'Area'<\/span>, <span style=\"color: #A020F0\">'Centroid'<\/span>});\r\nimshow(bw)\r\nhold <span style=\"color: #A020F0\">on<\/span>\r\n<span style=\"color: #0000FF\">for<\/span> k = 1:numel(s)\r\n  plot(s(k).Centroid(1), s(k).Centroid(2), <span style=\"color: #A020F0\">'b*'<\/span>);\r\n<span style=\"color: #0000FF\">end<\/span>\r\nhold <span style=\"color: #A020F0\">off<\/span><\/pre><p>There are several enhancements in the math area that interest me. For example, there are new numerical integration functions\r\n      (<tt>integral<\/tt>, <tt>integral2<\/tt>, <tt>integral3<\/tt>) that have more capabilities than the functions they replace (<tt>quad<\/tt> and its cousins). Try an integration over an unbounded interval using <tt>integral<\/tt>:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">fun = @(x) exp(-x.^2).*log(x).^2;\r\nintegral(fun,0,inf)<\/pre><pre style=\"font-style:oblique\">\r\nans =\r\n\r\n    1.9475\r\n\r\n<\/pre><p>With <tt>quad<\/tt> that didn't work so well:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">quad(fun,0,inf)<\/pre><pre style=\"font-style:oblique\">Warning: Infinite or Not-a-Number function value encountered. \r\n\r\nans =\r\n\r\n   NaN\r\n\r\n<\/pre><p>The <tt>griddata<\/tt> function now supports natural neighbor interpolation.\r\n   <\/p>\r\n   <p>And the <tt>unique<\/tt> function now has an additional option to preserve the original order of the data. I really like this one. The output of <tt>unique<\/tt> is normally sorted. Although you can postprocess the output to restore the original data order, it's tricky and I always\r\n      puzzled over it a bit. With the new optional argument, it's really easy.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">data = [3 2 9 4 8 1 1 10 1 2];\r\nunique(data)<\/pre><pre style=\"font-style:oblique\">\r\nans =\r\n\r\n     1     2     3     4     8     9    10\r\n\r\n<\/pre><p>You can see that the duplicates were removed and the result is sorted.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">unique(data,<span style=\"color: #A020F0\">'stable'<\/span>)<\/pre><pre style=\"font-style:oblique\">\r\nans =\r\n\r\n     3     2     9     4     8     1    10\r\n\r\n<\/pre><p>Now the original data order has been preserved.<\/p>\r\n   <p>There are several nice enhancements in the file import\/export area, including:<\/p>\r\n   <div>\r\n      <ul>\r\n         <li>.xlsx files can now be read on all platforms<\/li>\r\n         <li>FITS export<\/li>\r\n         <li>OPeNDAP protocol support (using the netcdf functions)<\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <p>Finally, if you are really into object-oriented programming using MATLAB, check out the new ability to <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/techdoc\/matlab_oop\/bs885dm.html\">control the set of allowed subclasses<\/a>, as well as the ability to <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/techdoc\/matlab_oop\/bs888fp.html\">control access to class members<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_88579f9a1f8e4383a425f94a46a02d9f() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='88579f9a1f8e4383a425f94a46a02d9f ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 88579f9a1f8e4383a425f94a46a02d9f';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Steve Eddins';\r\n        copyright = 'Copyright 2012 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_88579f9a1f8e4383a425f94a46a02d9f()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.14<br><\/p>\r\n<\/div>\r\n<!--\r\n88579f9a1f8e4383a425f94a46a02d9f ##### SOURCE BEGIN #####\r\n%%\r\n% Some of my fellow <https:\/\/blogs.mathworks.com MATLAB Central bloggers>\r\n% have already talked about the MATLAB R2012a release. Usually, I like to\r\n% scan the release notes and pick out just a few things that particularly\r\n% interest me. I encourage you to take a look at the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2012a\/techdoc\/rn\/rn_intro.html release notes> to\r\n% see what else is there that might interest you.\r\n%\r\n% I was particularly happy to see that the web browser system built into\r\n% MATLAB (used for various purposes, including the help system and the\r\n% publish feature) was completely overhauled so that it looks a lot better\r\n% on 64-bit Windows systems.\r\n%\r\n% Speaking of the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2012a\/techdoc\/matlab_env\/f6-22451.html publish>\r\n% feature, have you heard of it? It's a great way to turn a MATLAB script\r\n% (or function) into a web page, or a PDF, or a Word document. I use it to\r\n% create almost all of my blog posts. You can find a lot of examples online\r\n% by searching for the phrase \"Published with MATLAB\", such as\r\n% <http:\/\/www2.math.umd.edu\/~jmr\/241\/calc.html Calculus with MATLAB>.\r\n% Anyway, you can include syntax-highlighted code in your published output.\r\n% For example:\r\n%\r\n%   bw = imread('text.png');\r\n%   s = regionprops(bw, {'Area', 'Centroid'});\r\n%   imshow(bw)\r\n%   hold on\r\n%   for k = 1:numel(s)\r\n%     plot(s(k).Centroid(1), s(k).Centroid(2), 'b*');\r\n%   end\r\n%   hold off\r\n%\r\n% There are several enhancements in the math area that interest me. For\r\n% example, there are new numerical integration functions (|integral|,\r\n% |integral2|, |integral3|) that have more capabilities than the functions\r\n% they replace (|quad| and its cousins). Try an integration over an\r\n% unbounded interval using |integral|:\r\n\r\nfun = @(x) exp(-x.^2).*log(x).^2;\r\nintegral(fun,0,inf)\r\n\r\n%%\r\n% With |quad| that didn't work so well:\r\n\r\nquad(fun,0,inf)\r\n\r\n%%\r\n% The |griddata| function now supports natural neighbor interpolation.\r\n%\r\n% And the |unique| function now has an additional option to preserve the\r\n% original order of the data. I really like this one. The output of\r\n% |unique| is normally sorted. Although you can postprocess the output to\r\n% restore the original data order, it's tricky and I always puzzled over it\r\n% a bit. With the new optional argument, it's really easy.\r\n\r\ndata = [3 2 9 4 8 1 1 10 1 2];\r\nunique(data)\r\n\r\n%%\r\n% You can see that the duplicates were removed and the result is sorted.\r\n\r\nunique(data,'stable')\r\n\r\n%%\r\n% Now the original data order has been preserved.\r\n%\r\n% There are several nice enhancements in the file import\/export area,\r\n% including:\r\n%\r\n% * .xlsx files can now be read on all platforms\r\n% * FITS export\r\n% * OPeNDAP protocol support (using the netcdf functions)\r\n%\r\n% Finally, if you are really into object-oriented programming using MATLAB,\r\n% check out the new ability to\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2012a\/techdoc\/matlab_oop\/bs885dm.html control\r\n% the set of allowed subclasses>, as well as the ability to\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2012a\/techdoc\/matlab_oop\/bs888fp.html control\r\n% access to class members>.\r\n\r\n##### SOURCE END ##### 88579f9a1f8e4383a425f94a46a02d9f\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Some of my fellow MATLAB Central bloggers have already talked about the MATLAB R2012a release. Usually, I like to scan the release notes and pick out just a few things\r\n      that particularly... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2012\/04\/03\/matlab-r2012a\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[508,895,90,76,36,891,224,162,68,893,168,350],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/512"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=512"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/512\/revisions"}],"predecessor-version":[{"id":3785,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/512\/revisions\/3785"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}