필터 지우기
필터 지우기

Adding a title to save file that is dynamic

조회 수: 2 (최근 30일)
Theodore
Theodore 2013년 7월 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