. Advertisement .
..3..
. Advertisement .
..4..
Hi developer experts, I have a small but frustrating use case, and so far, I couldn’t get my head around this problem & ideal solution. I am running my command and facing one problem with the argument to dynamic structure reference must evaluate to a valid field name. Below is the command I used:
spectData{1} =
data: [256x26 double]
textdata: {1x26 cell}
colheaders: {1x26 cell}
Row: [256x1 double]
Col: [256x1 double]
Cho: [256x1 double]
Cho0x25SD: [256x1 double]
Cho0x2FCit: [256x1 double]
PCho: [256x1 double]
PCho0x25SD: [256x1 double]
SDdata = spectData{sliceNum - firstSlice}.(MetabMapSDString);
When I run it, I get the following error:
Argument to dynamic structure reference must evaluate to a valid field name.
I am looking forward to gaining some knowledge from all experts. Thank you, guys!
The cause:
You got this error because instead of passing a string, you mistakenly sent a cell array. Literal strings, on the other hand, are of the char array type. This error also appears in below program:
Solution:
You should check your field name, for example with
whos
and usef = char(f)
in your program.Matlab refers to a string as a cell. Literal strings are of type array. They print differently. A cell string prints as
While a regular char array prints,
The difference between the two functions is
cellstr
andchar
, which convert char arrays to strings.In your case,
char(MetabMapSDString)
should be used as the dynamic struct reference.