loading multiple xlsx files using for loop and readmatrix
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ektor
am 1 Dez. 2022
Kommentiert: Stephen23
am 1 Dez. 2022
Dear all,
I have a number of excel files with the names:
model_1.xlsx
model_2.xlsx
model_3.xlsx
.
.
.
model_100.xlsx
These files contain only numbers.
To simplify the analysis, let's assume that I want to load into Matlab the first, say, 7 excel files. So I do the following
model={'model_1', 'model_2','model_3', 'model_4', 'model_5', 'model_6', 'model_7'};
for k = 1:7
data=readmatrix(sprintf('model_%s.xlsx', model{k}))
end
But there must be a mistake in that code as it does not work.
Could you help me with that?
Thank you!
1 Kommentar
Stephen23
am 1 Dez. 2022
"But there must be a mistake in that code as it does not work"
Take a look at what your SPRINTF call returns:
model = {'model_1', 'model_2','model_3', 'model_4', 'model_5', 'model_6', 'model_7'};
sprintf('model_%s.xlsx', model{1})
Akzeptierte Antwort
David Hill
am 1 Dez. 2022
for k=1:7
data{k}=readmatrix(sprintf('model_%d.xlsx',k));%create cell array assuming the sizes are not the same
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!