avoid overwrite with xlswrite

3 次查看(过去 30 天)
Alessandro
Alessandro 2013-4-12
Hi,
I'm new in matlab and I'm trying to create an output from a text file. The script works well but until I create the excel file with the same name of the loading data.
Example:
% Load raw data d = load('dritto_dx_6.txt'); ..... ... % Open Excel file.
xlswrite('sac.xls', sac, 'sacbin', 'A2'); xlswrite('sac.xls', sacl, 'sacl', 'A2'); xlswrite('sac.xls', sacr, 'sacr', 'A2');
excelFileName = 'sac.xls'; excelFilePath = pwd; % Current working directory. sheetName = 'Foglio'; % Italian
Does someone know if it is possible to save the excel file with the same name of the loaded file? In other word, when I change the load file (es:dritto_dx_8.txt) the program overwrite data analyzed before (with 'dritto_dx_6.txt') to the new 'sac.xls' file. I need a “connection” so that when I change the load file its changes also the .xls file (maybe calling the excel file with the same name of the txt file to avoid my direct intervention every time changing the .xls filename).
Thnaks
Alessandro

回答(1 个)

Iman Ansari
Iman Ansari 2013-4-12
Hi. You can use a number after your output file name:
n=1;
excelFileName=sprintf('sac_%d.xls',n);
or
excelFileName=['sac_' num2str(n) '.xls'];

Community Treasure Hunt

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

Start Hunting!

Translated by