I have 429 numerical matrices of identical size (107 rows by 36 columns), stored inside sequentially named .mat files (e.g: subj_00000.mat ... subj_00428.mat). Here's what I need to do:
- Import into the MATLAB workspace.
- After importing, average all of them to generate another matrix, which will also have a dimension of 107x36.
- Finally, linearly correlate each column of the average matrix with each column of each of the original 429 matrices, to generate a new matrix of 429 rows and 36 columns.
So far I got to the stage of building a 107 x 36 x 429 array to be filled with my set of matrices.
S = dir(fullfile(D,'subj*.mat')); % D is the path where the .mat files are saved
N = numel(S);
C = cell(1,N); % preallocate cell array
for k = 1:N
S = load(fullfile(D,S(k).name));
C(k) = struct2cell(S);
end
A = cat(3,C{:}); % join all of the original matrices into a 107x36x429 array
M = mean(A,3)
but I get the following error message:
Reference to non-existent field 'name'.
Error in myscript (line 6)
S = load(fullfile(D,S(k).name));