Importing multiple files using a loop
조회 수: 12 (최근 30일)
이전 댓글 표시
Hello, i need to import multiple files and instead of writing them all down, i want to use a for loop for it.
These are the file names that i need to import, with 1 changing number in the file names.
A1=importdata('012_2023ef400t.txt');
A2=importdata('013_2023ef400t.txt');
A3=importdata('014_2023ef400t.txt');
this is the beginning, but i need to import 30 files.
Any suggestions?
Thank you!
채택된 답변
Dyuman Joshi
2023년 9월 28일
편집: Dyuman Joshi
2023년 9월 28일
This is a general idea -
n=30;
%Preallocate
A = cell(1,n);
%Storing data
for k=1:n
A{k} = importdata(sprintf('0%d_2023ef400t.txt', k+11));
end
Use indices to access the data in the stored array.
Depending upon the data you have, you can preallocate double or strings array instead of cell array.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!