split the name of a file (image .png)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Alberto Acri
el 25 de Nov. de 2022
Comentada: Image Analyst
el 25 de Nov. de 2022
I would like to change the name of this image:
'name_of_figure_BN_102.png'
to this name:
'name_of_figure_NB_102.png'
I tried splitting the name with 'strsplit' but it doesn't apply to my picture name because there is this '_' symbol.
Is there a simple method to change the name?
3 comentarios
Respuesta aceptada
Vilém Frynta
el 25 de Nov. de 2022
My way to do so would be as follows:
str1 = "name_of_figure_BN_102.png"; % Your input image name
strPieces = strsplit(str1,"_") % Splitting the name into pieces
strPieces(4) = "NB" % Editing "BN" to "NB"
% Reconstructing the name again
str2 = strcat(strPieces(1),"_", strPieces(2),"_", strPieces(3),"_", strPieces(4),"_", strPieces(5))
I am certain that there is a better way of reconstructing str2 and also there is a way to detect BN's position (and automatize this process). I only had few minutes to make this up. Hope it helps.
0 comentarios
Más respuestas (1)
Image Analyst
el 25 de Nov. de 2022
Here is one way:
fileName = 'name_of_figure_BN_102.png';
underlineLocations = strfind(fileName, '_')
index1 = underlineLocations(end-1) + 1;
index2 = underlineLocations(end) - 1;
fileName(index1 : index2) = fliplr(fileName(index1 : index2))
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!