Getting data from a struct array using dynamic field references

조회 수: 1 (최근 30일)
Thomas Koelen
Thomas Koelen 2015년 3월 24일
편집: Stephen23 2015년 3월 24일
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에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by