How to load multiple mat files from a folder in a sequence?

7 ビュー (過去 30 日間)
Tomaszzz
Tomaszzz 2021 年 12 月 10 日
編集済み: Stephen23 2021 年 12 月 10 日
Hi all,
I have folder with multiple mat files that I want to sequentially import into the workspace . I have the following script that produces the error claiming the file does not exists in the folder. One example file attached. Could you please help?
%% get participant file names and start loop
all_files = dir(fullfile(Folder, '*.mat'));
for files_i = 1 : length(all_files)
% read in data
disp(all_files(files_i).name)
data = load(fullfile(all_files(files_i).name));
% execute what I want
end
Error using load
Unable to read file 'XsensData_ID001_T001_mat.mat'. No such file or directory.

採用された回答

Stephen23
Stephen23 2021 年 12 月 10 日
編集済み: Stephen23 2021 年 12 月 10 日
S = dir(fullfile(Folder, '*.mat'));
for k = 1:numel(S)
F = fullfile(Folder,S(k).name); % you need FOLDER here too.
data = load(F);
% execute what I want
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by