how to get all the variables from a struct

1 view (last 30 days)
Hello,
I have a struct with 50 variables. the old code I get uses the variables directly, but I cannot access them so. for example, here is my struct "DATA" with a field "age", and the uses the variable "age" directly. newage=age+10 So to adjust the code, i need to use newage=DATA.age+10, and this can be done once (but not for 100 variables times and not when the variables is used 100 times in the code) So I look for a simple way to do this procedure. Can you help?

Accepted Answer

Stephen23
Stephen23 on 9 Feb 2018
Edited: Stephen23 on 9 Feb 2018
Download and use Matt J's handy function for generating all of those variables automatically:
The link that Matt J provided as rationale for that submission is now dead, but I think that this one should be a reasonable alternative:

More Answers (1)

Walter Roberson
Walter Roberson on 9 Feb 2018
If you only need the updated data, then adjust the data at the beginning of the code.
If you need both data, then at the beginning of the code, create a second struct containing the updated data and make the changes to your code to refer to the new name. You would not be able to do that automatically as you would need to make a decision at each point as to which of the two versions you needed, but the control-F replace-and-find can help a lot.

Categories

Find more on Structures in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!