Getting data from a struct array using dynamic field references

4 次查看(过去 30 天)
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
  1 个评论
Stephen23
Stephen23 2015-3-24
编辑:Stephen23 2015-3-24
The difference is simple:
  • () parentheses refer to the cells themselves.
  • {} curly braces refer to the cell contents.
You can read more about indexing cell arrays in the documentation.

请先登录,再进行评论。

采纳的回答

per isakson
per isakson 2015-3-24
Replace
data.(OECFMES(1))
by
data.(OECFMES{1})

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by