1

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; 
1
  • 3
    Valid field names begin with a letter, and can contain letters, digits, and underscores. Commented Jul 25, 2014 at 12:49

2 Answers 2

3

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 
Sign up to request clarification or add additional context in comments.

Comments

2

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.

2 Comments

Thanks, Do you have idea, whether it is available in MATLAB version R2010b SP1
In R2010b, use genvarname.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.