Struct field name with space or special character

25 次查看(过去 30 天)
Hi,
For table name, we can use space or special character when using stiring type.
However for the structure varailble,it doesn't work. Is there a way to have space in structure field names?
thanks,
  2 个评论
Stephen23
Stephen23 2024-2-19
编辑:Stephen23 2024-2-19
This sounds like you are putting meta-data into the fieldnames. Remember that meta-data is data, and data belongs in variables not in their field/variable names. forcing meta-data into field/variable names will make your code fragile (e.g. like this question hints at), slow, and complex. Best avoided.

请先登录,再进行评论。

回答(2 个)

Stephen23
Stephen23 2024-2-17
移动:Matt J 2024-2-18
"Is there a way to have space in structure field names?"
No.

Matt J
Matt J 2024-2-18
Another option is to use dictionaries, which are a bit more similar to structs than tables, e.g.
secretID=["Steve Rogers", "Tony Stark", "Donald Blake"];
hero=["Captain America","Iron Man","Thor"];
d=dictionary(secretID,hero);
out = d("Steve Rogers")
out = "Captain America"

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by