getfield() error when calling on multiple fields: "Struct contents reference from a non-struct array object"

조회 수: 11 (최근 30일)
Hello,
I have searched around for a good couple of hours but I cannot figure out how to properly use getfield() to call on multiple fields.
What works:
getfield(MyStruct(8), 'field1')
or
getfield(MyStruct(8), 'field2')
Whwat does NOT work:
getfield(MyStruct(8), 'field1', 'field2')
Among many other variations... I have tried specific indexing, so on and so forth. MyStruct is a 1X44 with 10 fields.
Thanks in advance!
  댓글 수: 2
Brandon  Madsen
Brandon Madsen 2018년 1월 25일
This function is genuinely buggy and does not work as advertised. You can pull up the code and fix it manually for your machine though, since the code for this function is accessible. I can show you how later if you need help.
camilo sanchez
camilo sanchez 2018년 1월 26일
I could look into that, even though I have never tried to edit a native function.
Anythign specific to watchout for when approaching this task?
Thanks!

댓글을 달려면 로그인하십시오.

채택된 답변

Nicolas Schmit
Nicolas Schmit 2018년 1월 26일
Which version of MATLAB are you using? The documentation says that getfield() can access nested fields, not that you can retrieve multiple fields at a time.
  댓글 수: 2
camilo sanchez
camilo sanchez 2018년 1월 26일
I am using 2017a and 2017b.
I suppose I misinterpreted the description where it says: "....The getfield function supports multiple sets of field and fIndx inputs..."
But if you can only get one field at a time (per getfield() call), then I will stop trying.
Thank you!
Walter Roberson
Walter Roberson 2018년 1월 26일
Look at the examples and observe that specifying multiple field names is used to access nested values.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by