Code to automatically generate filename from reading cell in an excel file
1 次查看(过去 30 天)
显示 更早的评论
Hello, its been a while since I used MATLAB and I seem to be having problems.
What Im trying to do: To read an excel file (specific cells) > name file using a series of those cells.
ie cell 1 = C2, cell 2 = 2013_02_25, cell 3 = WE08GYD >> file saved as C2_2013_02_25_WE08GYD.pdf
The code i'm using:
[~,~,testcll] = xlsread('Book1.xlsx','Sheet2','A1'); % 'C2';
[~,~,testdate] = xlsread('Book1.xlsx','Sheet2','A2'); %'2013_07_07';
[~,~,testnumber] = xlsread('Book1.xlsx','Sheet2','A3'); %21;
testtype = 'FTP75';
[~,~,vehicle] = xlsread('Book1.xlsx','Sheet1','D1'); %'Y654GYD';
% filename = -['WARNING TEST FILE_' testcll(1,1)] % <<<< Failing
% filename = sprintf('WARNING TEST FILE_%s_%s_%s_%s_%s', testcll, testdate,
% testnumber, testtype, vehicle) % <<<< Failing
% filename = ['WARNING TEST FILE_', testcll, '_', testdate, '_',
% testnumber, '_', testtype, '_', vehicle] % <<<< Failing
saveas(tst2, filename, 'pdf')
I've tried several things with sprintf (i think thats what is supposed to be used) but it can't seem to deal with the imported information being in a cell
Any help would be appreciated.
3 个评论
回答(1 个)
Iman Ansari
2013-4-18
filename = ['WARNING TEST FILE_C2_2013-02-25']
filename(filename=='-')='_'
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!