Reputation: 25
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:
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));
Upvotes: 1
Views: 252
Reputation: 25
You are looping over S yet overwriting it every time. Rename the S that is inside the loop. While you are at it I would give all your variables meaningful names--there is no need to use a single letter every time. – svdc
Thank you! I renamed
S = load(fullfile(D,S(k).name));
as
T = load(fullfile(D,S(k).name));
and it worked
Upvotes: 0