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 CenterFile Exchange에서 Low-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