Iterate through a loop using the alphabet.

18 Ansichten (letzte 30 Tage)
Joseph
Joseph am 5 Okt. 2011
Kommentiert: Alvaro Gaona am 12 Aug. 2018
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!

Akzeptierte Antwort

the cyclist
the cyclist am 5 Okt. 2011
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 Kommentare
Sean de Wolski
Sean de Wolski am 5 Okt. 2011
Also, 'a':'z'
will create the above string.
Alvaro Gaona
Alvaro Gaona am 12 Aug. 2018
Now it's easier.
for letter='a':'z'
filename = ['001', letter,'.txt']
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by