MATLAB: How to generate a sequence of variable matrices from data stored in multiple .mat files

variables

I have a number of similarly named files each with a differing number of columns and two variables, height & weight.
Group1.mat,. . . ,GroupN.mat
How do I grab each file and separate the variables into their own values?
Height1,…,HeightN Weight1,…,WeightN
I tried this:
FileTotal = dir('*.mat');
i = length(FileTotal);
for k = 1:i
Height{k} = FileTotal.height
Weight{k} = FileTotal.weight
end
I've tried other things as well. No luck

Best Answer

Files = dir('*.mat'); % all mat files in the folder
N = length(Files); % total number of files
Height = cell(N,1) ; % initialize heights
Weight = cell(N,1) ; % initialize weights
for k = 1:N % loop for each file
load (Files(k).name) % load the file
Height{k} = height ;
Weight{k} = weight ;
end
Related Question