Loading text files by looping through two number sequences

1 view (last 30 days)
I have 1800 files that I wanna loop through. They're named cut1_1 to cut90_20. The first number goes from 1 to 90 and the second number goes from 1 to 20. I understand that I have to have two loops but loading each file onto solidworks is giving me a hard time.

Accepted Answer

Walter Roberson
Walter Roberson on 15 Aug 2019
You do not need two loops. You can use a routine such as https://www.mathworks.com/matlabcentral/fileexchange/10959-sort_nat-natural-order-sort to sort the file names into numeric order.
However, using two loops should be easy enough:
for casenum = 1 : 90
for subsetnum = 1:20
filename = sprintf('cut%d_%d', casenum, subsetnum);
do something with filename
end
end

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!