Prev: question regarding nested function structure and fsolve
Next: Manipulation of robot with joystick in Simmechanics
From: Rachel Laughs on 17 Nov 2009 11:39 user selects a file using "uigetfile" and now I want to extract text from that file name. The file names will always be in a variation of this format: directory\The_File_01.ext directory\TheFile_01.ext (where the extension is always the same, and there is ALWAYS two number digits following an underscore before the extension) What I need to collect: 1. the pathname 2. the filename WITHOUT the last two numbers, but INCLUDING all of the underscores 3. the two numbers following the final underscore any ideas? I've run fresh out. thanks!
From: Miroslav Balda on 17 Nov 2009 12:10 "Rachel Laughs" <remove.thisrachellaughs(a)gmail.com> wrote in message <hdujjo$224$1(a)fred.mathworks.com>... > user selects a file using "uigetfile" and now I want to extract text from that file name. The file names will always be in a variation of this format: > > directory\The_File_01.ext > directory\TheFile_01.ext > > (where the extension is always the same, and there is ALWAYS two number digits following an underscore before the extension) > > What I need to collect: > 1. the pathname > 2. the filename WITHOUT the last two numbers, but INCLUDING all of the underscores > 3. the two numbers following the final underscore > > any ideas? I've run fresh out. thanks! Hi, the following code solves your task: [filename,pth] = uigetfile(......); % The path is in pth I = findstr('_',filename); file = filename(1:I(end)); Mira
From: Rachel Laughs on 17 Nov 2009 13:02 "Miroslav Balda" <miroslav.nospam(a)balda.cz> wrote in message <hdule1$rkp$1(a)fred.mathworks.com>... > Hi, > the following code solves your task: > [filename,pth] = uigetfile(......); % The path is in pth > I = findstr('_',filename); > file = filename(1:I(end)); > Mira ah, that is brilliant!! Thank you very much. I was not aware of the findstr function and your genius use of it! thanks!! by the way, what would you suggest for extracting the two numbers at the end of the filename? Something about textscan perhaps?
From: Rachel Laughs on 17 Nov 2009 13:09 "Rachel Laughs" <remove.thisrachellaughs(a)gmail.com> wrote in message <hduofa$8u1$1(a)fred.mathworks.com>... > > by the way, what would you suggest for extracting the two numbers at the end of the filename? Something about textscan perhaps? oh wait, nevermind. I just expanded on your use of "I" thanks again
From: Loren Shure on 17 Nov 2009 15:34
In article <hdujjo$224$1(a)fred.mathworks.com>, remove.thisrachellaughs(a)gmail.com says... > user selects a file using "uigetfile" and now I want to extract text from that file name. The file names will always be in a variation of this format: > > directory\The_File_01.ext > directory\TheFile_01.ext > > (where the extension is always the same, and there is ALWAYS two number digits following an underscore before the extension) > > What I need to collect: > 1. the pathname > 2. the filename WITHOUT the last two numbers, but INCLUDING all of the underscores > 3. the two numbers following the final underscore > > any ideas? I've run fresh out. thanks! > You might check out the function fileparts -- Loren http://blogs.mathworks.com/loren |