Adding a title to save file that is dynamic

2 次查看(过去 30 天)
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!

采纳的回答

dpb
dpb 2013-7-30
编辑:dpb 2013-7-31
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..." :)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by