Clear Filters
Clear Filters

Hello everyone. I would like to ask that how to use for loop statement to import. Mat file.Thanks a lot.

1 view (last 30 days)
for Q= 1:numel(s)
% dunedata= dlmread(['M' num2str(Q) '.mat']);
filename = '['M' num2str(Q) '.mat']';
m = matfile(filename);
ds = datastore(['M' num2str(Q) '.mat']);
data=load(['M' num2str(Q) '.mat']);
% file_list = reshape( dir('Day*.mat'), 1,[] );
% for saf = file_list
% dh = sscanf(, 'Day%d_hour%d' );
% data = load( );
% LoadData{ dh(1), dh(2) } = data;
% end
for i =1:length(F)
.mat file:

Accepted Answer

Shashank Gupta
Shashank Gupta on 25 May 2021
Hi Wesley,
You can use dir function to list down all mat files and then use load function to load the mat file in workspace. Below is the sample code which you can refer.
% List all the mat file
lis = dir("**/*.mat");
for loop
load(filename); % you can use to get the filenames.
I hope this helps.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!