Hi, I need to copy data from individual excel files from 33 participants, and paste all in one excel file. I did it for the first sheet and then for the second sheet, etc. The problem is that some of the files have 4 sheets and some have 6 sheets. Also, some of the sheets do not have data. Therefore the script stops when there is no data. How can I force it to continue and report the missing data? The following stops when data doesn't exist.
first_data = true; for i=2:34 sheet=6; STIMroot='C:\Users\ski\CloudStation\Zahra\dissertation\data analysis\behavioral data analysis\monolingualSTIM\'; Drop='C:\Users\ski\CloudStation\Zahra\dissertation\data analysis\behavioral data analysis\monolingualSTIM\final.xls'; STIMfile=strcat(STIMroot,num2str(i),'\',num2str(i),'.xls'); %get the STIM file
if exist(STIMfile,'file') STIMdata = xlsread( STIMfile,sheet); data2=STIMdata(:,3:5); if first_data == true; export_data = data2; first_data = false; else export_data = horzcat(export_data,data2 ); end else warningMessage = sprintf('Warning: file does not exist:\n%s',h); continue; end end xlswrite(Drop,export_data,1);
Best Answer