0

I would like to read several CSV files in MATLAB.

The names of the files are as follows:

data_00001.csv,
data_00002.csv,
...,
data_00010.csv,
data_00011.csv,
...,
data_00100.csv,
data_00101.csv,
...,
data_01000.csv,
data_01001.csv,
...

I would like to know how I can update the name (i.e., number of zeros in the csv file name) and read these files using "for" loop in MATLAB.

rahnema1
  • 15,264
  • 3
  • 15
  • 27
NJE
  • 37
  • 7

1 Answers1

1

You can use sprintf and readmatrix:

for i = 1: 10000
    name = sprintf ('data_%0.5d.csv', i);
    mat = readmatrix (name ); % or mat = csvread (name );
    % ...
end
rahnema1
  • 15,264
  • 3
  • 15
  • 27