Hello,
I am trying to load and append several matlab files. Each .mat file has 2 1x1 structures, a Data struct (has 12 fields, each with 1x50 cells), and a Settings struct (10 fields).
I'd like to load 2 (or more) .mat files, and compare the settings. I've found the STRUCTCMP function, which works well. If the settings are the same, I'ld like to append the Data structs for the two mat files so that the fields stay the same, but now each has 1x100 cells.
I have a few problems with my code. First, when I load the file, I'd like to rename each structure so that data1 = data; and settings1 = settings; but I haven't figured out how to do this in the loop. Second, I'm not sure how to increase the size of the structure array, data.
dataNum = input('How many data files to analyze? ')
for a = 1:dataNum
data{a} = strcat('data',num2str(a));
Settings{a} = strcat('Settings',num2str(a));
end
for i = 1:dataNum
PData = input('What is the filename? ','s');
load(PData)
Settings(i) = settings;
if i >1
if ~STRUCTCMP(settings1,settings(i)
fprintf('Error: data files have different settings')
settings(i)
break;
end
end
data(i) = Data;
i = i+1;
end
data = [data1 data2];
names = fieldnames(data);
cellData = cellfun(@(f) {vertcat(data.(f))},names);
data = cell2struct(cellData,names);
Thanks for your help, this is my first analysis script, and my first time posting on the forum. Christina