Filter löschen
Filter löschen

Read Multiple Files with While Loop

1 Ansicht (letzte 30 Tage)
Daniella Chait
Daniella Chait am 20 Sep. 2022
Kommentiert: Stephen23 am 20 Sep. 2022
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 Kommentare
Walter Roberson
Walter Roberson am 20 Sep. 2022
Is there a particular reason to use a while loop instead of a for loop?
Stephen23
Stephen23 am 20 Sep. 2022
"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:

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Chunru
Chunru am 20 Sep. 2022
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

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by