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

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.

1 件のコメント

Ashish Uthama
Ashish Uthama 2011 年 7 月 12 日
Why would you want to do this? If you have a use-case, people here might be able to give you a better answer.

サインインしてコメントする。

 採用された回答

Jan
Jan 2011 年 7 月 12 日

2 投票

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.

その他の回答 (3 件)

Paulo Silva
Paulo Silva 2011 年 7 月 12 日

0 投票

No and would be a bad idea if you could do it.
Bjorn Gustavsson
Bjorn Gustavsson 2011 年 7 月 12 日

0 投票

Try to avoid such nonsense asap. Nothing good can come out of that. If you somehow want a [ or another non-"alphanum" character in a variable name you should take a step back and rethink your design. Stick to 0-9 a-z A-Z and _!

1 件のコメント

Sadanand
Sadanand 2011 年 7 月 14 日
Sorry.. I am beginner in Matlab.. I was not knowing variable naming convention..

サインインしてコメントする。

Walter Roberson
Walter Roberson 2011 年 7 月 12 日

0 投票

Perhaps the containers.Map class would be suitable for you; see http://www.mathworks.com/help/techdoc/matlab_prog/brqqo5e-1.html

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

タグ

質問済み:

2011 年 7 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by