Group fields of structure with same first n letters of field name

6 views (last 30 days)
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!

Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!