Iterate through a loop using the alphabet.

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!

 Accepted Answer

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 Comments

That is excellent, thank you very much.
The answers on here are always quick and usually very useful!
Also, 'a':'z'
will create the above string.
Now it's easier.
for letter='a':'z'
filename = ['001', letter,'.txt']
end

Sign in to comment.

More Answers (0)

Categories

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

Products

Asked:

on 5 Oct 2011

Commented:

on 12 Aug 2018

Community Treasure Hunt

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

Start Hunting!