Open files in loop and perform operations

4 ビュー (過去 30 日間)
Abhiram B R
Abhiram B R 2021 年 5 月 11 日
回答済み: Vineet Joshi 2021 年 5 月 19 日
I have many files of the type data_1_9.txt, data_1_15.txt, data_2_9.txt, data_2_15.txt, data_3_9.txt, data_3_15.txt, .........data_200_9.txt, data_200_15.txt.
I need to open two files at a time, perform some operations and then save it to a file.Something like this
load data_1_9.txt, data_1_15.txt
perform some operations
save it as something like data_1.txt
similarly for all 200 files
How can i write a for loop for this operation

採用された回答

Vineet Joshi
Vineet Joshi 2021 年 5 月 19 日
Hi
The following routine might help your task.
You can use the dir function to get the names of all the text files in a directory.
Once you have the list you can simply use a for loop with a step size of 2 and load consecutive file and perform your operation.
fprintf will help you in writing the output text file.
Hope this helps.
Thanks

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by