I have s structure field named d.NL330260 and a temporary variable grade_n which is a 1x1 cell array containing 'NL330260'. I tried implementing the following:
grade_n = 'NL330260';
d.(grade_n)
but , I get this error message.
Argument to dynamic structure reference must evaluate to a valid field name.
What could be the problem??

 채택된 답변

Steven Lord
Steven Lord 2016년 10월 5일

1 개 추천

This is not the exact code you were using:
grade_n = 'NL330260';
d.(grade_n)
It was more like:
grade_n = {'NL330260'};
d.(grade_n)
When using dynamic field names, the dynamic field name must be a char row vector. You were passing in a scalar cell array with a char row vector inside the cell, but that's different. Using char as you did is one way to resolve the problem; another is to extract the char row vector from the cell.
grade_n = {'NL330260'};
d.(grade_n{1})

추가 답변 (1개)

na ja
na ja 2016년 10월 5일

0 개 추천

OK, solved it. I put it in this way:
grade_n = 'NL330260';
d.((char(grade_n) ))

댓글 수: 2

Jan
Jan 2016년 10월 5일
Use Steven's suggestion of indexing with {1} instead of the slower converions by CHAR().
na ja
na ja 2016년 10월 7일
thanks Jan

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

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

2016년 10월 5일

댓글:

2016년 10월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by