Problem to read multiple .csv in a loop for.

3 Ansichten (letzte 30 Tage)
Tony Castillo
Tony Castillo am 22 Okt. 2020
Kommentiert: Tony Castillo am 22 Okt. 2020
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);
  2 Kommentare
Rik
Rik am 22 Okt. 2020
Please do not post duplicates.
Have you tried learning to use the debugger to step through you code line by line?
If you would use the smart indentation, you would notice that you've put the cd inside your loop. Luckily it does nothing, as you didn't change the current directory (nor should you: readtable allows you to specify a full or relative path).
The line with Irr_=[Irr]; looks like you want to store something over several iterations of your loop. However, you aren't changing the variable at all here.
Tony Castillo
Tony Castillo am 22 Okt. 2020
Mr Rik, I apologize for creating a post twice, but in the first post the platforms got an error and it was the reason why I made another dealing with tha same topic.
You were right about Irr_=[Irr], I changed it to "Irr_=[Irr_, Irr];"
Thank you for your help

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 22 Okt. 2020
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);
  2 Kommentare
Tony Castillo
Tony Castillo am 22 Okt. 2020
Thank you for your help
Ameer Hamza
Ameer Hamza am 22 Okt. 2020
I am glad to be of help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by