Hello!
There's probably a simple tool for this, but I can't find it:
Have a string for a file name that includes the full path, like:
C:\Users\DougAnderson\Documents\MATLAB\SHtest\sig hole 1.xlsx
where the last part (the actual file name) may contain spaces. I would like to change this to, for example
sig hole 1
Thanks
Doug

 Respuesta aceptada

Chad Greene
Chad Greene el 11 de Dic. de 2014
Editada: Chad Greene el 11 de Dic. de 2014

5 votos

You can use fileparts. I had to switch the direction of the slashes because I'm using a mac, but it should work on your machine keeping the slashes the way you wrote them:
[~,name,~] = fileparts('C:/Users/DougAnderson/Documents/MATLAB/SHtest/sig hole 1.xlsx')
name =
sig hole 1

2 comentarios

Sean de Wolski
Sean de Wolski el 11 de Dic. de 2014
Chad, fullfile will handle filesep for you.
fullfile('C:\Documents/MATLAB')
Chad Greene
Chad Greene el 11 de Dic. de 2014
Ah, very cool!

Iniciar sesión para comentar.

Más respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 11 de Dic. de 2014

1 voto

s='C:\Users\DougAnderson\Documents\MATLAB\SHtest\sig\hole 1.xlsx'
out=regexp(s,'(?<=\\)[^\\]+$','match')

1 comentario

Douglas Anderson
Douglas Anderson el 11 de Dic. de 2014
Thank you, Azzi. I thought I might have to go to "regexp()" to get this done, but "fileparts()" makes my task simpler!

Iniciar sesión para comentar.

Douglas Anderson
Douglas Anderson el 11 de Dic. de 2014

0 votos

Ah, Perfect!!!! Thank you, Chad.

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 11 de Dic. de 2014

Comentada:

el 11 de Dic. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by