i have multiple excel files in D:\ directory these files name starting with "gt" characters i need to delete all empty rows in these files in , Sheet1 only and store processed files in other names ,
Q :\ The following code has been successfully deleted all empty rows but from single file , how we can applied it to all files in D:\ directory and their names start with "gt" characters ? the following code which i mention above …
projectdir = 'D:'FileNames = dir(fullfile(projectdir, 'gt*.xls'));j=1;for i=1:length(FileNames)FileToLoad = fullfile(projectdir, FileNames(i).name);[~, ~, data] = xlsread(FileToLoad,'Sheet1');data(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x), data)) = {''};ii = 1;while truetryif any(strcmp('', data(ii,:))) % find rows with empty cell
data(ii,:) = []; % remove the row
elseii = ii+1;endcatchbreak % When the process goes beyond the end, stop the loop.
endendoutputfile = fullfile(projectdir, 'result{i}.xls');xlswrite(outputfile, data);end
i hope to get output like :
gt1.xls file store as result1.xls file ; gt2.xls file store as result2.xls file ; and so on ....
Best Answer