2017-08-05 87 views
0

我有一个大小为248 * 15的单元矩阵,其最大列数为15.我想提取MatLab中包含大于或等于8(> = 8)非零列条目的行。如何根据单元矩阵中的列数选择行?

例如:电池行1,2,7,8,......

Find attached image

+0

为什么downvote?这是一个有效的问题。但是,添加示例代码或您迄今为止尝试过的代码是指示性的,并且显示了努力。查看下面的解决方案,让我知道它是否有效。 – crazyGamer

回答

1

可以使用cellfun来首先确定哪个电池元件是空的,然后使用数组索引到根据需要选择行:

C = {} % The cell matrix of size 248 x 15. 

% An array of 248 x 15 that has Booleans based on empty or not: 
emptyCells = cellfun(@isempty, C) 

% The total number of empty columns on each row: 
emptyColsCount = sum(emptyCells, 2) 

% Find those rows with at least 8 non-zero columns 
requiredRowIndices = find(emptyColsCount < 8) 
% This returns [1, 2, 7, ...] 
+0

是的...它的工作.. –