Loading multiple mat files using for loop

3 vues (au cours des 30 derniers jours)
Kumar
Kumar le 12 Nov 2020
Commenté : KSSV le 12 Nov 2020
Hello,
I would like to load multiple mat files in a particular folder. Right now i have 8 matfiles so i have written the code as below.
for k=1:8
S = load(sprintf('M%d.mat',k));
I donot to limit the number of files in code. Is there a way to find the matfiles in a folder and load all the mat files present in the folder.
  1 commentaire
KSSV
KSSV le 12 Nov 2020
This question discussed to death in mathworks........a simple google will give you tonns of links.

Connectez-vous pour commenter.

Réponse acceptée

Ameer Hamza
Ameer Hamza le 12 Nov 2020
Modifié(e) : Ameer Hamza le 12 Nov 2020
You can use dir() command to iterate over all the .mat files. For example
files = dir('*.mat');
for i = 1:numel(files)
S = load(files(i).name)
end

Plus de réponses (0)

Catégories

En savoir plus sur Workspace Variables and MAT Files dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by