Load files with similar name

Good morning, I have as an output from an optimization software 8760 csv files.
They are all nominated as user_1.csv, user_2.csv, user_3.csv ... etc till user_8760.csv.
I have to load all of them in Matlab, but I don't know how to do that in a smart and fast way.
Can you please help me?
Thank you!

 Accepted Answer

Stephen23
Stephen23 on 23 Dec 2021
Edited: Stephen23 on 23 Dec 2021
P = 'absolute or relative path to where the files are saved';
S = dir(fullfile(P,'user_*.csv'));
for k = 1:numel(S)
F = fullfile(P,S(k).name);
S(k).data = readtable(F); % or READMATRIX
end
See:

More Answers (1)

Image Analyst
Image Analyst on 23 Dec 2021
You've asked a FAQ, so see the FAQ:
It's one of the top 2 or 3 FAQQY FAQs that we see here.

Categories

Products

Release

R2020b

Tags

Community Treasure Hunt

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

Start Hunting!