i have strings like these:
s{1,2} = 'string';
s{2,2} = 'string2';
and in workspace structure like this
U.W.string = [2 2.5 3]
I want to check (in loop) s{1,2} or s{2,2} or s{i,2} matches any structure with the same name. If so, assign values from this structure to some variable var(i). How can it be done?
Use
isfieldsto check, if a string is the name of a field in a struct. Then use the syntaxstruct.(name), wherenameis a string to access the field. Your code might look something like:This converts the initial struct
to this one
A shorter implementation is achieved by removing the inner loop and giving a cell-array to
isfields: