Iterate through a loop using the alphabet.
조회 수: 17 (최근 30일)
이전 댓글 표시
Hello,
I am looking to loop through a few files names that differ only by one letter, i.e they go 001a, 001b, 001c etc.
What is the simplest way to put set the loop up, so that it changes the value of the letter each time.
For example ideally i want:
For x=a:z
filename = ['001' ,x '.txt']
Or something similar.
Can this be done?
Kind regards
Joe Harris
Apologies if the question isn't worded very well!
댓글 수: 0
채택된 답변
the cyclist
2011년 10월 5일
Here's one way:
s = char(97:122) % Or just use: s = 'abcdefghijklmnopqrstuvwxyz';
for ns = 1:length(s)
filename = ['001',s(ns),'.txt']
end
댓글 수: 3
Alvaro Gaona
2018년 8월 12일
Now it's easier.
for letter='a':'z'
filename = ['001', letter,'.txt']
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!