Clear Filters
Clear Filters

How do I generate a sequence of variable matrices from data stored in multiple .mat files?

1 view (last 30 days)
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

Accepted Answer

KSSV
KSSV on 10 Mar 2017
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

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!