Group fields of structure with same first n letters of field name
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, My data looks like this:
image1_control,
image1_drug,
image1_drug2,
image2_control,
image2_drug2,
image3_drug,
image4_control,
image4_drug2,
etc
These are all field names of a structure.
I would like to group field names based on the first 7 characters of the string. For example, I want to create a structure named image1 with subfields named control, drug1 and drug2.
I have tried using strcmp, but I would have to create a for loop to conduct a pairwise comparison. I'm having trouble using regexp and indexing all "images" with the matching names.
Can someone help me find a more efficient way to group field names that share the first 7 characters?
Thanks!
1 commentaire
Walter Roberson
le 10 Juil 2017
Duplicate merged into original https://www.mathworks.com/matlabcentral/answers/348110-matching-first-n-characters-of-string-in-array
Réponses (0)
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!