From: Chris Rock on
Hi,

I'm putting together a little file to read data from an XLS, conduct some analysis, and then write the summary to another (new) XLS.

I'm using a "uigetfile" for the user to select the source XLS, and currently this writes a variable called "Data" which contains the source filename as a character array (single entry, 1 x 21 char array). Is there anyway I can use some of the characters in this character array as part of the filename for the summary XLS I'm creating?

Currently, my code for the xlswrite stage looks like this:

xlswrite('Summary.xls', Summary, 'Trip Summary', 'A1');

Ultimately, I want the new XLS filename to look something like "Summary_04072010.xls", with the date section being from the "Data" character array. Hopefully I've made sense here!

Any help would be really gratefully appreciated!

Thanks,
Chris
From: Steven_Lord on


"Chris Rock" <chris.rock(a)cenex.co.uk> wrote in message
news:i43fl5$som$1(a)fred.mathworks.com...
> Hi,
>
> I'm putting together a little file to read data from an XLS, conduct some
> analysis, and then write the summary to another (new) XLS.
>
> I'm using a "uigetfile" for the user to select the source XLS, and
> currently this writes a variable called "Data" which contains the source
> filename as a character array (single entry, 1 x 21 char array). Is there
> anyway I can use some of the characters in this character array as part
> of the filename for the summary XLS I'm creating?

Certainly. A char array is just like any other array -- you can extract a
piece of it using indexing, you can concatenate it with another char array,
you can modify elements.

S = 'myfile1.txt';
[pathname, filename, extension] = fileparts(S);
newfilename = [filename '_version2' extension]
% or
newfilename = [S(1:7) '_version2' S(8:end)]

There are more string (=char array) manipulation functions listed in HELP
STRFUN, and there are a few functions specifically for filename manipulation
in HELP IOFUN.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com