You have a reference to an element in a data structure, which you want to pass to a function. Not the value itself, but the reference. And you don't like to use evil eval constructions. Therefore, you convert the reference into a structure, like liked by Matlab's built-in subsref and subsasgn functions.
For example, to reference the value a(12), you would have to convert '(12)' into
def =
type: '()'
subs: {[12]}
And to reference a(12).field_b{1,3}{2}((3:4),:).c, you would need to convert '(12).field_b{1,3}{2}((3:4),:).c' into
def(1) =
type: '()'
subs: {[12]}
def(2) =
type: '.'
subs: {'field_b'}
def(3) =
type: '{}'
subs: {[1] [3]}
def(4) =
type: '{}'
subs: {2}
def(5) =
type: '()'
subs: {[3 4] ':'}
def(6) =
type: '.'
subs: {'c'}
The assignment is correct when any sub-structure reference that is accepted by subsref and subsasgn is correctly converted from a string to a valid structure.
Note: Solutions wrapped in (f)eval(c), inline, str2func, regexprep (dynamic regular expressions), etc, are not appreciated.
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers8
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15805 Solvers
-
1797 Solvers
-
Calculate the Levenshtein distance between two strings
1511 Solvers
-
Return unique values without sorting
1013 Solvers
-
How many trades represent all the profit?
619 Solvers
More from this Author31
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!