Matlab - With ... End of Structure

Does Matlab have a kind of command ... end? http://msdn.microsoft.com/en-us/library/wc500chb(v=vs.80).aspx

I have a variable in my workspace that contains a lot of nested data. Now I do not want to type this all the time:

Root.ChildLevel1.A = Root.ChildLevel1.B + Root.ChildLevel1.C 

But rather something like:

 with Root.ChildLevel1 A = B + C end 

Is it possible?

+4
source share
2 answers

I do not know about such functionality in Matlab.
What you can do is

 cur = Root.ChildLevel1; cur.A = cur.B + cur.C; 

Edit:
According to @Nick's comment, if Root.ChildLevel1 is not a subclass of handle , then add the following line:

 Root.ChildLevel1 = cur; 

I would also recommend

 clear cur; 

in the end.

+3
source

I have to say that I do not recommend using this function very often, but once I tried the FEX fee, which allows you to unpack structures.

Of course, you still need to update the structure after performing the calculations, so I only use it for subfunctions that mainly use the structure as input.

I'm not sure, but I think this is the one I tried:

http://www.mathworks.com/matlabcentral/fileexchange/26216-structure-fields-to-variables

+1
source

All Articles