Doug Hull, MathWorks
(Originally posted on Doug's MATLAB Video Tutorials blog.)
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 "Clutter classification" 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 "dot parens notation", or Dynamic Field Names as they are formally known.
a.doug = 'Hull'
a.jiro = 'Doke'
name = 'doug';
last = a.doug
eval(['last = a.' name]) %BAD
last = a.(name) %GOOD
Recorded: 20 Aug 2008
Featured Product
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to change your settings.