Stuart’s MATLAB Videos

Watch and Learn

Dynamic field name usage

This short video shows how you can make your code shorter, more flexible, and readable by using a string variable to reference a field in a structure. This is called dynamic field name reference or “dot parens” notation. You can say: fName = ‘doug’ a.(fName) %this now refers to a.doug
In this particular example, a MATLAB user was writing out dozens of different cases, when one loop with dynamic field name reference makes the code so much easier.
I would also like to take this opportunity to welcome Dan Sutoyo, of Blink Dagger fame, to The MathWorks. Dan first came on to my radar when he started posting about MATLAB and commenting on this blog. Eventually we got talking about job opportunities at The MathWorks and I referred him for a position starting in the Engineering Development Group. Thanks for accepting the job and I hope to see you guest posting your tutorials here soon.
|
  • print

评论

要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。