Can I load .mat files in a loop?

4 vues (au cours des 30 derniers jours)
Qianqian Pan
Qianqian Pan le 20 Juil 2017
Commenté : Stephen23 le 21 Juil 2017
Hi,
I have 10 files namely img120.mat, img121.mat, img122.mat, img123.mat, img124.mat, img125.mat, img126.mat, img127.mat, img128.mat, img129.mat. RGB values saved in each .mat file.
I would like to load each .mat file, then imshow(RGB) to look at each image. Would it be possible to load all the .mat files in a loop rather than do load img120.mat, imshow(RGB), followed by load 121.mat, imshow(RGB), and so on and so forth...

Réponse acceptée

Matt J
Matt J le 20 Juil 2017
Modifié(e) : Matt J le 20 Juil 2017
filenames={'img120','img121',...};
for i=1:numel(filenames)
S=load(filenames{i});
imshow(S.RGB)
end

Plus de réponses (1)

James Tursa
James Tursa le 20 Juil 2017
Another way:
filenumbers = 120:129; % <-- or whatever number range you want
for k=filenumbers
S = load(['img' num2str(k)]);
imshow(S.RGB)
end

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by