MATLAB: How to create variable with special characters like [ ] { } etc

variable

I need to create variables having special characters like [ ] { } in workspace. For Example create variable with name variable_name_s[pop]. I am not sure whether it is possible or not in Matlab. Please let me know about this. Thanks.

Best Answer

It works. The names of variables are stored as C-strings, which can be modifed in a MEX function. But it will have the drawback, that you cannot access the variables anymore: If the interpreter parses the symbol 'name{i}' it uses 'name' as name of the variable and the part in the curly braces as cell index. Therefore the interpreter will not search for a variable called 'name{i}', and in consequence it will not find it. I think CLEAR is a better method to make a variable unaccessible.
This can be used to rename field names of structs freely: FEX: RenameField. Together with dynamic fieldnames they can be accessed, e.g. S.('name[{]}'). But I have never seen a useful application for such dirty tricks.