MATLAB Answers

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

조회 수: 1(최근 30일)
Wesley
Wesley 2021년 5월 23일
답변: Shashank Gupta 2021년 5월 25일
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( saf.name, 'Day%d_hour%d' );
% data = load( saf.name );
% LoadData{ dh(1), dh(2) } = data;
% end
F=dir('*.mat');
for i =1:length(F)
load(F(i).['M'num2str(i)])
end
.mat file:

채택된 답변

Shashank Gupta
Shashank Gupta 2021년 5월 25일
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 lis.name to get the filenames.
end
I hope this helps.
Cheers.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by