{"id":2128,"date":"2008-08-20T10:23:56","date_gmt":"2008-08-20T15:23:56","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2008\/08\/20\/advanced-matlab-dynamic-field-names\/"},"modified":"2016-05-18T11:29:18","modified_gmt":"2016-05-18T15:29:18","slug":"advanced-matlab-dynamic-field-names","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2008\/08\/20\/advanced-matlab-dynamic-field-names\/","title":{"rendered":"Advanced MATLAB: Dynamic field names"},"content":{"rendered":"<p>We have MATLAB users come into The MathWorks to present their work in MATLAB from time to time. Recently there was an interesting presentation with some really great &#8220;Clutter classification&#8221; algorithms in a GUI. One of the questions that came out of that discussion was how to get rid of a bunch of EVAL statements from their code. The following code shows how they can be avoided using &#8220;dot parens notation&#8221;, or Dynamic Field Names as they are formally known.<\/p>\n<p>a.doug = &#8216;Hull&#8217;<br \/>\na.jiro = &#8216;Doke&#8217;<\/p>\n<p>name = &#8216;doug&#8217;;<\/p>\n<p>last = a.doug<br \/>\neval([&#8216;last = a.&#8217; name]) %BAD<br \/>\nlast = a.(name) %GOOD<\/p>\n<p><embed src=\"https:\/\/blogs.mathworks.com\/images\/pick\/\/FlashVideos\/FlowPlayer.swf?config=%7Bembedded%3Atrue%2CplayList%3A%5B%7BsuggestedClipsInfoUrl%3A%2780%20see%20also%2Etxt%27%2Curl%3A%2780%20Advance%20Dot%20parens%20notation%2Eflv%27%7D%5D%2CbaseURL%3A%27http%3A%2F%2Fblogs%2Emathworks%2Ecom%2Fimages%2Fpick%2FFlashVideos%2F%27%2CsplashImageFile%3A%2780%20Advance%20Dot%20parens%20notation%2Ejpg%27%2Cloop%3Afalse%2CinitialScale%3A%27fit%27%2CshowFullScreenButton%3Afalse%2CautoBuffering%3Afalse%2CmenuItems%3A%5Bfalse%2Cfalse%2Cfalse%2Cfalse%2Cfalse%2Ctrue%5D%2CautoPlay%3Afalse%7D\" type=\"application\/x-shockwave-flash\" width=\"500\" height=\"400\"><\/embed><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have MATLAB users come into The MathWorks to present their work in MATLAB from time to time. Recently there was an interesting presentation with some really great &#8220;Clutter&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/08\/20\/advanced-matlab-dynamic-field-names\/\">read more >><\/a><\/p>\n","protected":false},"author":68,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,8,2],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2128"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2128"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2128\/revisions"}],"predecessor-version":[{"id":7344,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2128\/revisions\/7344"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}