フィルターのクリア

read multiple excel file and apply process on it using matlab

2 ビュー (過去 30 日間)
ahmed obaid
ahmed obaid 2015 年 8 月 18 日
コメント済み: ahmed obaid 2015 年 8 月 19 日
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 true
try
if any(strcmp('', data(ii,:))) % find rows with empty cell
data(ii,:) = []; % remove the row
else
ii = ii+1;
end
catch
break % When the process goes beyond the end, stop the loop.
end
end
outputfile = 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 ....

採用された回答

Walter Roberson
Walter Roberson 2015 年 8 月 18 日
That code appears to loop over the desired files, but it always writes the output to the same file 'gt.xls'. You may wish to use
xlswrite(FileToLoad, data)
  2 件のコメント
Walter Roberson
Walter Roberson 2015 年 8 月 18 日
Make sure you specify the path for the file when you open it. Using fullfile() is usually a good idea.
projectdir = 'D:'
FileNames = dir(fullfile(projectdir, 'gt*.xls'));
FileToLoad = fullfile(projectdir, FileNames(i).name);
...
outputfile = fullfile(projectdir, 'gt.xls');
xlswrite(outputfile, data);
ahmed obaid
ahmed obaid 2015 年 8 月 19 日
thank you sir , i have modified my code but also not write my interested output its write only 1 excel file , hope to get the following output
gt1.xls file store as result1.xls file ;
gt2.xls file store as result2.xls file ;
and so on ....
please sir can you modified and submit the full code .. thanks again

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by