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 次查看(过去 30 天)
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

回答(1 个)

Frantisek Gaspar
Frantisek Gaspar 2022-11-26
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!

Translated by