I need to take the data of more than 100 excel files. I have managed to obtain the name of each one of the files but when I use readmatrix it gives me an error.

1 view (last 30 days)
clear all;
clear; %With these code I can create the names of all the files who have a
clc; %similar name to the file I posted. But when i try to use readmatrix
stations= ["C042","C057","C061","C067"]; %using the variable filename, it says that filename doesn't exist.
parameters=["AirTemp","Precipitation","WindSpeed"]; %I would appreciate your help.
for station=stations %Thanks
for parameter=parameters
for month=01:12
filename=sprintf("%s_%s_2021%02d.csv",station,parameter,month)
data= readmatrix("PROJECT\PROJECTDATA\'filename'")
end
end
end

Answers (1)

Frantisek Gaspar
Frantisek Gaspar on 26 Nov 2022
For reading tabular data I recomend readtable function. The function can be set to handle various files and is quite robust. If there are multiple files I alos recoment datastore function which can make the loading more convenient,

Community Treasure Hunt

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

Start Hunting!