file name manipulation
Mostrar comentarios más antiguos
I have a file name that takes the form: S_1_X_Y where X can be an integer between 1-16, and Y is a letter a,b,c,d.
I want to be able to just replace the number X by a user defined value.
any help greatly appreciated. Thanks
1 comentario
Jason
el 6 de Mayo de 2011
Respuesta aceptada
Más respuestas (1)
Teja Muppirala
el 6 de Mayo de 2011
NUM2STR is useful for stuff like this.
Y = {'a' 'b' 'c' 'd'}
for jj = 1:4
for n = 1:9
filename = ['S_1_' num2str(n) '_' Y{jj}]
end
end
Or alternatively, if you need to have zeros in there like '001', '002', '003' then you can use SPRINTF instead of NUM2STR
n = 7;
filename = ['S_1_' sprintf('%03.f',n) '_a']
n = 61;
filename = ['S_1_' sprintf('%03.f',n) '_a']
3 comentarios
Oleg Komarov
el 6 de Mayo de 2011
num2str supports the format:
num2str(1,'%03.f')
Jason
el 6 de Mayo de 2011
Oleg Komarov
el 6 de Mayo de 2011
I edited my answer. Check it out.
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!