Adding a title to save file that is dynamic

5 views (last 30 days)
Hello. I was wondering for saving images or writing xls files if there was a way to add additional wording in the title for dynamic names. For example I have:
b = csvread(source_files(j).name);
savecsv= source_files(j).name;
And when writing an image/csv I can get it to reproduce whatever the file is named after the run, but I want to add to the end of the file name so for example
b = csvread(source_files(j).name);
savecsv= source_files(j).name;
biggarr=[date minmaxmean];
[status,message] = xlswrite(savecsv,biggarr);
Will give me Antelope Lake.xls for the first run. Is there a way to make it so that when I save different arrays of information I have different names. For example:
Run 1: Antelope Lakemaxtemp.xls Antelope Lakemintemp.xls
Run 2: Ruby Lakemaxtemp.xls Ruby Lakemintemp.xls
I basically just want to add on to the dynamically changing file name so that I have different files for specific variable/arrays. Thanks!

Accepted Answer

dpb
dpb on 30 Jul 2013
Edited: dpb on 31 Jul 2013
Sure, just build a new filename instead of reusing the old one...use pieces of the old if desired, of course. You just have to have some way to decide what the new piece(s) are to be. Here I just stored them as an array internally; you may want something more clever...knock your socks off in that regard. :)
stuff={'maxtemp';'mintemp'}; % the new pieces for file names
...
for i=1:length(sourcefiles)
...
[p,n,e]=fileparts(sourcefiles(1).name); % path,name,extension
% do what to get max temp's and ready to write
outname=strcat(n, stuff(1), e);
xlswrite(outname,biggarr);
% now get min temp's and ready to write
outname=strcat(n, stuff(2), e);
xlswrite(outname,biggarr);
...
This will duplicate your sample cases above for each pass thru the loop on multiple files.
As always, "salt to suit..." :)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!