从只有一个值的字符串数组中删除行

Delete rows from string array with just one value

我有一个这样的字符串数组:

x={{'Na','Mg','Si'};{'V'};{'Na','Mg','Si','S'};{'Si'};{'Na','Mg','Al','P'}}

如何删除所有只包含一个值的行,得到:

x={{'Na','Mg','Si'};{'Na','Mg','Si','S'};{'Na','Mg','Al','P'}}

您没有 "string array", you have a cell array containing cell arrays (in turn these contain chars).

x={{'Na','Mg','Si'};{'V'};{'Na','Mg','Si','S'};{'Si'};{'Na','Mg','Al','P'}}

可以用

得到每个sub-cell中的元素个数
N = cellfun( @numel, x );

然后使用

删除具有单个元素的sub-cells
x = x( N > 1 );

这可以在一行中完成

x = x( cellfun(@numel, x) > 1 );