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!

 採用された回答

the cyclist
the cyclist 2011 年 10 月 5 日

4 投票

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 件のコメント

Joseph
Joseph 2011 年 10 月 5 日
That is excellent, thank you very much.
The answers on here are always quick and usually very useful!
Sean de Wolski
Sean de Wolski 2011 年 10 月 5 日
Also, 'a':'z'
will create the above string.
Alvaro Gaona
Alvaro Gaona 2018 年 8 月 12 日
Now it's easier.
for letter='a':'z'
filename = ['001', letter,'.txt']
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

質問済み:

2011 年 10 月 5 日

コメント済み:

2018 年 8 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by