MATLAB: Problem to read multiple .csv in a loop for.

csvfor loopMATLAB

Hi all,
I have one problem to read multiple ."csv" tables and also process them because appears this error message "Error using readtable (line 223)
Unable to open file 'Dailydata_(i).csv'."
%%%%Leer y extraer datos de una CSV
current_path = pwd;
close all
Irr_=ones(25,1);
for i=1:2
T = readtable('Dailydata_(i).csv', 'PreserveVariableNames', true);
I=T(:,3);
A=table2array(I); %
Irr=A(1:25);
Irr(isnan(Irr))=0;
M=max(Irr);
m=mean(Irr);
size(Irr);
Irr_=[Irr];
cd(current_path);
end
z=ones(25,2);
I2=([Irr_].*z);

Best Answer

In the line
T = readtable('Dailydata_(i).csv', 'PreserveVariableNames', true);
MATLAB does not recognize i as a numeric value. You need to use sprintf(). For example, if file name is Dailydata_(1).csv then write
T = readtable(sprintf('Dailydata_(%d).csv', i), 'PreserveVariableNames', true);