MATLAB Answers

How do I use sprintf for files numbered from 0 till 15?

5 ビュー (過去 30 日間)
Eveline 2015 年 3 月 11 日
コメント済み: Eveline 2015 年 3 月 11 日
I try to use the function sprintf in order to import data in a certain folder. The workbooks are numbered as "Experiment_A_0", "Experiment_A_1", ..., "Experiment_A_15".
Unfortunately only the workbooks 1-15 are imported now, while I also need workbook 0.
My code now is:
for fileNum = 1:numFiles
fileName = sprintf('Experiment_A_%1d.xls',fileNum); %%Define file-name
[A(:,fileNum),B(:,fileNum),C(:,fileNum),D(:,fileNum),E(:,fileNum),F(:,fileNum)] = importfile(fileName,sheet,range);
Thanks in advance!


Greig 2015 年 3 月 11 日
The first value of fileNum is 1, so the first file is "Experiment_A_1", and "Experiment_A_0" is never reached in the loop. Update the fileName line to ....
fileName = sprintf('Experiment_A_%1d.xls',fileNum-1);
This will start at "Experiment_A_0"
  1 件のコメント
Eveline 2015 年 3 月 11 日
Thanks a lot!!


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by