I have field name which contains (.) for matlab structure
When I create structure, it throws invalid field name error
e.g
fieldName = 'Freq.01' Structure
s.(fieldName) = 25; I have field name which contains (.) for matlab structure
When I create structure, it throws invalid field name error
e.g
fieldName = 'Freq.01' Structure
s.(fieldName) = 25; As pointed out in Yuans's comment, fieldnames must not contain '.'. This may be the case because the Value of a field can be another field. Maybe you want to replace the '.' with '_' and then use your new valid fieldname:
fieldname = 'Freq.01'; fieldname = strrep(fieldname, '.', '_'); s.(fieldname) = 25 s.('hello').('world') = 17 You can use matlab.lang.makeValidName to convert an invalid name such as 'Freq.01' into something that is a valid name. (This is only available in relatively recent versions of MATLAB).
In older versions of MATLAB, you can use genvarname.