if string is abc return value
Mostrar comentarios más antiguos
Hi.
I have filename is string and then I want to find specific name.
if filename have ' a ' xxx = 1
if filename have ' b ' xxx = 2
if filename have ' c ' xxx = 3
thank you.
7 comentarios
Jan
el 9 de Abr. de 2019
Please explain more details. What does "filename have ' a '" mean? Start with an 'a' or contain an 'a' anywhere?
if filename(1) == 'a'
or
if any(filename == 'a')
Jassy
el 9 de Abr. de 2019
Jan
el 9 de Abr. de 2019
With the space between the "a" and the ".jpg"? What should happen for "b#####a .jpg"? Is "#" a digit? Please do not let the readers guess the details.
Jassy
el 9 de Abr. de 2019
Adam Danz
el 9 de Abr. de 2019
So, it's always the last letter of the filename?
Respuesta aceptada
Más respuestas (1)
Adam Danz
el 9 de Abr. de 2019
The cell array 'key' lists all possible last-characters and the order determines the value.
filename = 'Z2q0002b.jpg';
[~, fName] = fileparts(filename);
key = {'a' 'b' 'c'};
xxx = find(strcmp(key, fName(end)));
xxx =
2
Categorías
Más información sobre Thermal Analysis 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!