How to read several files

2 ビュー (過去 30 日間)
G SY
G SY 2022 年 7 月 26 日
コメント済み: KSSV 2022 年 7 月 26 日
Hello
I have several mat files which are named as following.
Inv_A_1.raw.mat , Inv_A_2.raw.mat , Inv_A_3.raw.mat
Inv_B_1.raw.mat , Inv_B_2.raw.mat , Inv_B_3.raw.mat
Inv_C_1.raw.mat , Inv_C_2.raw.mat
Inv_D_1.raw.mat , Inv_D_2.raw.mat , Inv_D_3.raw.mat
I want to use a for loop then I can load each file in each step of the loop.
Thanks in advance for your help
  1 件のコメント
G SY
G SY 2022 年 7 月 26 日
I already wrote a a code to read several file.
cd 'path'
file_mat = dir('*.mat');
N_file=length(file_mat);
for ind= 1:N_file
load(file_mat(ind).name);
end
But in this code all caracter of the name of the files that I can load are same except a number.

サインインしてコメントする。

回答 (1 件)

KSSV
KSSV 2022 年 7 月 26 日
編集済み: KSSV 2022 年 7 月 26 日
files_mat = dir('*.mat'); % your pwd is where mat files are present if not give path
N_file=length(files_mat); % total number of files
% loop for each file
for ind= 1:N_file
thisFile = files_mat(i).name ;
load(thisFile);
% Do what you want
end
  2 件のコメント
G SY
G SY 2022 年 7 月 26 日
thank you
KSSV
KSSV 2022 年 7 月 26 日
Thanks is accpeting the answer.. :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by