Is it possible to use a variable name like this within Matlab?

1 回表示 (過去 30 日間)
Leon
Leon 2019 年 10 月 17 日
コメント済み: Leon 2019 年 10 月 17 日
I have standardized header names with slash like this: OXYGEN_UMOL/KG.
How do I escape the '/' so that I can use commands like this?
OXYGEN_UMOL/KG = 5;
The same variable name should go to my Excel writetable command.
Thanks!
  2 件のコメント
Daniel M
Daniel M 2019 年 10 月 17 日
It is not possible with regular variable names. The only time is may be possible is with the names of variables within a table, and then only in release R2019b. Unfortunately, I have R2019a so I cannot test this.
Leon
Leon 2019 年 10 月 17 日
Thank you!

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

採用された回答

Guillaume
Guillaume 2019 年 10 月 17 日
編集済み: Guillaume 2019 年 10 月 17 日
Confusingly, variable names can mean two different things now in matlab. A generic variable name, e.g.
>> A = 5
is limited to alphanumeric characters and _ and cannot start with a digit.
Since R2019b, table variable names on the other hand can have any characters in them, so yes a table variable can be named OXYGEN_UMOL/KG.
One way to do this:
>> t = table([1;2;3], ["aaa"; "b"; "cc"], 'VariableNames', {'OXYGEN_UMOL/KG', 'Name with spaces'})
t =
3×2 table
OXYGEN_UMOL/KG Name with spaces
______________ ________________
1 "aaa"
2 "b"
3 "cc"
Another way:
>> t.('#@!') = [10;20;30]
t =
3×3 table
OXYGEN_UMOL/KG Name with spaces #@!
______________ ________________ ___
1 "aaa" 10
2 "b" 20
3 "cc" 30
writetable will write these names as is in excel or a text file.
  2 件のコメント
Adam Danz
Adam Danz 2019 年 10 月 17 日
編集済み: Adam Danz 2019 年 10 月 17 日
Thanks, I hadn't thought about tables.
Leon
Leon 2019 年 10 月 17 日
Many thanks, Everyone!
Glad this works with table after R2019b.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by