Read Multiple Files with While Loop

I have about 20 files that I need to read and manipualte data. How would I write a while loop so that it will read the file, extract data, then continue to read the next file, etc. ?

댓글 수: 2

Walter Roberson
Walter Roberson 2022년 9월 20일
Is there a particular reason to use a while loop instead of a for loop?
Stephen23
Stephen23 2022년 9월 20일
"How would I write a while loop so that it will read the file, extract data, then continue to read the next file, etc. ?"
The standard approach is to use a FOR loop:

댓글을 달려면 로그인하십시오.

답변 (1개)

Chunru
Chunru 2022년 9월 20일

0 개 추천

fn = dir("*.dat"); % or your file name pattern
for i=1:length(fn)
fn_c = fn(i).name % current filename to be processed
% do processing for fn_c
end

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2022a

태그

질문:

2022년 9월 20일

댓글:

2022년 9월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by