I have 5 MAT-files and 1 RAR-files in the directory 'Database'. Then I want to load MAT-files only from the directory. This is the code :
clear all; clc;
files = dir(strcat(pwd,'\Database\'));
for x = 1 : size(files,1)
[path{x}, name{x}, ext{x}] = fileparts(files(x).name);
end
for x = 1 : size(files,1)
if strcmp(ext{x},'.mat')
load(strcat(pwd,'\Database\',name{x},'.mat'));
end
end
---------------------------------------------------------
This code is used to load MAT-files only from the selected directory. You can change the directory by changing
files = dir(strcat(pwd,'\Directory\'));
And you also can change the file extention by changing
if strcmp(ext{x},'Any file extention')
and
load(strcat(pwd,'\Directory\',name{x},'Any file extention'));
Best Answer