I have a .mat file containing a bunch of structure variables which I need to loop through. The structure names differ based on the conditions of the trial whose data they represent. For example, subject1_treatment1_baseline_1, subject1_treatment1_post_1, subject1_treatment2_baseline_1, etc. Let's assume all the trials are subject1 and end with "_1". I realize this is not a good way to name these structures and that this information could be stored in fields within each, but the .mat file was exported from a program that automatically named the structures based on the data filename from which they were exported. So, at present, I have created cell arrays containing lists of the treatments and test times and a loop to cycle through the structure names that looks something like this:
treatment = {'treatment1','treatment2','treatment3'};testtime = {'baseline','post'};for t=1:length(treatment) for tt=1:length(testtime) trialname = ['subject1_' treatment{t} '_' testtime{tt} '_1']; % Here's where I would like to use "trialname" to access the data in each structure in the workspace and perform calculations.
endend
So, my question is, if the structures in the workspace are already named this way, is there a way I can access the structure in the workspace having the name stored in "trialname" without using eval?
Best Answer