MATLAB: Getting data from a struct array using dynamic field references

indexingstructures

I have a struct that looks like this:
data =
GS_L: {411x9 cell}
GS_R: {27x9 cell}
GS_U: {27x9 cell}
GS_D: {27x9 cell}
and a cell that looks like this:
OECFMES =
'GS_L'
'GS_R'
'GS_U'
'GS_D'
But when I try to acces data from the struct I get this error message.
>> data.(OECFMES(1))
Argument to dynamic structure reference must evaluate to a valid field name.
When I type it manually like this:
data.('GS_L')
It does work however
What am I doing wrong?
Kind regards,
Thomas Koelen

Best Answer

Replace
data.(OECFMES(1))
by
data.(OECFMES{1})