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 个评论

Is there a particular reason to use a while loop instead of a for loop?
"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 个)

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by