Using load for different files with varying names

2 visualizaciones (últimos 30 días)
Miraboreasu
Miraboreasu el 13 de Sept. de 2022
Editada: Stephen23 el 14 de Sept. de 2022
I have 25 files with .mat files, naming from data1 to data25
how to load them properly without manualy typing from 1 to 25
Here is my idea and the error
```
for i = 1:1:25
load('data%d.mat',i)
end
```
Error using load
Must be a text scalar.

Respuesta aceptada

Akira Agata
Akira Agata el 13 de Sept. de 2022
How about the following?
for kk = 1:25
fileName = sprintf('data%d.mat', kk);
load(fileName)
%
% Some process for each file
%
end
  2 comentarios
Stephen23
Stephen23 el 14 de Sept. de 2022
Editada: Stephen23 el 14 de Sept. de 2022
@Miraboreasu: Note that LOADing directly into the workspace often leads to problems processing the loaded data, exactly as your follow-up question indicates:
It is strongly recommended to LOAD into an output variable:
S = load(..)
and then access the fields of S.
Akira Agata
Akira Agata el 14 de Sept. de 2022
Yes, of course it is recommended to load into an output variable, as you mentioned.
Thank you for your additional comment !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by