Create a string variable with a value same as the name of an imported csv file

Hi
After importing a csv file I see that a variable 'textdata' has been created. It is identified by curly brackets. In row 1, column 1 is the information I want. Here's an example:
This is the name of the CSV file:
C:\Program Files\BOSE\Etienne\Data files\WW series_block tests\WW11cRH_29May2012.TXT
I want to create a variable as follows:
SampleDescrip='WW11cRH-29May2012'
(Ideally I want to replace the underscore in the original name with a dash).
Thank you.

 Accepted Answer

regexprep('WW11cRH_29May2012.TXT','_','-')
EDIT
name = 'C:\Program Files\BOSE\Etienne\Data files\WW series_block tests\WW11cRH_29May2012.TXT';
[path,n] = fileparts(name);
SampleDescrip = regexprep(n,'_','-');

5 Comments

Thanks Oleg,
This is very helpful.
Can help with the main part of the question please? That is, how do I create the SampleDescrip variable based on the name of the CSV file?
Thanks Oleg, This too is a big help. I'm stuck at an earlier hurdle though.
After loading my CSV file I have three items visible in my workspace labelled colheaders, data and textdata
So I did the following and got an error:
name=textdata(1,1); % Row 1, column 1 contains the file path and name which I want to use
[path,n] = fileparts(name);
??? Error using ==> fileparts at 17
Input must be a row vector of characters.
Can you help further please?

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!