I am creating a script to be universal in opening pre-made Data files that hold the same basic information, but the original files are not consistent in how they are named.
An example, the same variable has 3 different variants in the different files:
Data01.SubData
Data01.SubData_01
Data01.SubData01
Is there a way to ask Matlab to look for and call any variables that start with "Data01.SubData" regardless of the the final characters in the name? Any help is appreciated.
Sure, you can use
fieldnames
to get a list of names, do your matching, then grab the field you want:If the confusion is at the top level rather than at the substruct level, you can do the same thing by loading your .mat file into another struct, rather than dumping the variables directly into the workspace:
mydata = load('somefile.mat');