Struct field name with space or special character

24 vues (au cours des 30 derniers jours)
Pete sherer
Pete sherer le 17 Fév 2024
Modifié(e) : Stephen23 le 19 Fév 2024
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 commentaires
Dyuman Joshi
Dyuman Joshi le 17 Fév 2024
You could use underscore in place of space.
Stephen23
Stephen23 le 19 Fév 2024
Modifié(e) : Stephen23 le 19 Fév 2024
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.

Connectez-vous pour commenter.

Réponses (2)

Stephen23
Stephen23 le 17 Fév 2024
Déplacé(e) : Matt J le 18 Fév 2024
"Is there a way to have space in structure field names?"
No.

Matt J
Matt J le 18 Fév 2024
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"

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by