As part of a university project, I have to do the following: Use a database that contains 14 different folders (14 different subjects) and in every folder we have 5 trials of 12 different activities stored in .mat files. The trials files contain 6 columns (of which I want only 3) and different size of rows. Now I want to concatenate the 5 trials in one .mat folder for every subject, and store all the database to the following format : subject x activity x trial .
I have written the following code:
InPath_data = 'C:\Users\olga\Desktop\USC-HAD\';
listname = [InPath_data, 'Subjects.txt'];
folder_subject = textread(listname,'%s','delimiter','\n','whitespace','');
listname = [InPath_data,'ActivityTrial.txt'];
files_act_tr = textread(listname,'%s','delimiter','\n','whitespace','');
fname = [InPath_data,folder_subject{1},'\',files_act_tr{1},'.mat'];
tmp1= [];
k=1;
for i=1:length(folder_subject)
for j=1:length(files_act_tr)
fname = [InPath_data,folder_subject{i},'\',files_act_tr{j},'.mat'];
tmp= load(fname);
q=tmp.sensor_readings( : ,(1:3));
tmp1= cat(1,tmp1,q);
clear q;
if mod(j,5)==0
data(j-4*k,:,:)=tmp1;
k=k+1;
tmp1=[];
end
end
end
Now when clearing tmp1 i cannot use the loop. I suspect that using cell arrays is the key to do what I want, but I have never used them before, so... Any help would be appreciated! :)