Using load for different files with varying names
조회 수: 3 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Akira Agata
2022년 9월 13일
How about the following?
for kk = 1:25
fileName = sprintf('data%d.mat', kk);
load(fileName)
%
% Some process for each file
%
end
댓글 수: 2
Stephen23
2022년 9월 14일
편집: Stephen23
2022년 9월 14일
@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
2022년 9월 14일
Yes, of course it is recommended to load into an output variable, as you mentioned.
Thank you for your additional comment !
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!