如何用string和数字值删除整个行

我需要使用matlab编程删除excel文件中的空列的所有行。 我有多个Excel文件,数据格式如下:

admin img1 1 admin img2 1 admin img3 1 admin img4 1 

我需要删除所有这些文件中不包含任何数据的所有空白行。

我发现了一个很好的代码片段,它满足了我的要求,但它只是删除数字数据。

Q:\下面的代码删除所有只包含数字数据的行,如果删除行包含string数据,那么我们需要做哪些types的修改?如果我有很多的excel文件,还有一件事呢?

 e = actxserver ('Excel.Application'); %// open Activex server ewb = e.Workbooks.Open('c:\test\test.xlsx'); %// open file (enter full path) eur = ewb.ActiveSheet.UsedRange; %// lets simplify using active sheet data = cell2mat(eur.Value); %// get numeric data idx = find(any(isnan(data),2))'; %'// find rows with empty (or text) cells for k=idx(end:-1:1) eur.Rows.Item(k).Delete; %// delete entire row from the last one end ewb.Save %// save to the same file ewb.Close(false) e.Quit 

这是我的解决scheme。 我使用testxls.xlsx作为示例源。 它有空单元格。

首先导入文件:使用导入模块并将数据导入为单元格数组。 导入模块可以为您生成代码,以便以后可以批处理所有文件。

 [~, ~, data] = xlsread('C:\Users\xxx\Documents\MATLAB\testxls.xlsx','Sheet1'); data(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x), data)) = {''}; 

然后处理单元格数组,放弃有空单元格的行。 然后将结果数组保存到excel文件中。

 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 xlswrite('processed.xlsx', data) 

你有没有尝试过:1.突出显示列或行2.单击编辑选项卡,然后select转到3.然后select特殊,然后空白4.然后回到家,在单元格下,您可以删除行或列