Naming figures with existing filename

Hello Community,
I am having trouble getting the naming of my figures right. What I want to do is use part of a variable that contains an existing file name. For example: baseFileName = IMG_1234.jpg, and I want the title for the subsequent figure to read as, 'RGB 1234'. I have tried various iterations of code, an example of which is:
figure('name', 'RGB (regexpi(baseFileName, (?<=IMG_)\d+', 'match', 'once'))', 'numbertitle', 'off');
but obviously the section referring to 'regexpi(baseFileName,...etc.' would also appear in the title which is not what I want. The regexpi line of code has worked sucessfully elsewhere so I know this is correct, but I'm struggling to insert it in to the correct part of naming the figure.
This is for a script that will be run a few times using different images and I want to store the images after with their correct ID in the title for future reference.
So, can anyone offer some useful advice please?
Regards,
10B.

 Respuesta aceptada

Ilham Hardy
Ilham Hardy el 20 de En. de 2016
Perhaps this might works?
figT = ['RGB ' (regexpi(baseFileName, (?<=IMG_)\d+', 'match', 'once'))];
figure('name', figT, 'numbertitle', 'off');

3 comentarios

Hello Illham,
Thanks for your comment. Actually I tried something like this earlier:
ImgName = regexpi(baseFileName, '(?<=IMG_)\d+', 'match', 'once');
which produces the variable ImgName = 1234, then I wrote:
figure('name', ImgName, 'numbertitle', 'off');
which writes the '1234' to the figure title, but... the 'RGB ' part is missing.
When I tried your version as above, I get the following error:
figT = ['RGB ' (regexpi(baseFileName, (?<=IMG_)\d+', 'match', 'once'))];
|
Error: Unexpected MATLAB operator.
which unusually is saying that the 'less than' operator is in error - so, I'm still not sure of the way forward!
Hello,
Apparently you've missed a colon in your example.
It should be:
figT = ['RGB ' (regexpi(baseFileName, '(?<=IMG_)\d+', 'match', 'once'))];
instead of
figT = ['RGB ' (regexpi(baseFileName, (?<=IMG_)\d+', 'match', 'once'))];
Hope this helps, IH
10B
10B el 21 de En. de 2016
Ah - the curse of the missing colon! (or single inverted comma). That's it, sorted perfectly. Thanks a lot for your help.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 20 de En. de 2016
You're probably referring to the annoying feature of title where it treats the letter following an underline as a subscript. You can turn off that annoying default feature by using the 'Interpreter' option in title(), xlabel(), or ylabel():
baseFileName = 'IMG_1234.jpg';
[~, baseNameNoExtension, ~] = fileparts(baseFileName);
title(baseNameNoExtension, 'Interpreter', 'none'); % No subscript now - YAY!!!
Or if you just plain don't want the underline, replace it with a space:
baseFileName = 'IMG_1234.jpg';
[~, baseNameNoExtension, ~] = fileparts(baseFileName);
baseNameNoExtension(baseNameNoExtension == '_') = ' ';
title(baseNameNoExtension, 'Interpreter', 'none');

1 comentario

10B
10B el 21 de En. de 2016
Do you know Image Analyst, your suggestion wasn't exactly what I was looking for, but, as it turns out is very good information in any case as I am now going to use this in the script to for generating the 'caption' title for the figure as well. Great stuff - thanks a lot for your input!

Iniciar sesión para comentar.

Categorías

Productos

Preguntada:

10B
el 20 de En. de 2016

Comentada:

10B
el 21 de En. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by