How to retrieve a word from a filename

1 vue (au cours des 30 derniers jours)
Jagadeesh p
Jagadeesh p le 6 Mai 2012
name:"rgb_watermark_lena.jpg"
I want to retrieve only "lena" word from file
It should be "lena.jpg"
Can any one sort out this problem

Réponse acceptée

Jakob Sørensen
Jakob Sørensen le 6 Mai 2012
name = 'rgb_watermark_lena.jpg';
name(end-7:end-4)
ans =
lena
You probably get the point :)

Plus de réponses (1)

Neil Caithness
Neil Caithness le 6 Mai 2012
It rather depends on how general you want it. Here's another example that may help you decide.
filename = 'rgb_watermark_lena.jpg';
[~, name, ext] = fileparts(filename);
nameparts = regexp(name, '_', 'split');
newfilename = fullfile([nameparts{end} ext])

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by