'Delete rows from string array with just one value
I have a string array like this:
x={{'Na','Mg','Si'};{'V'};{'Na','Mg','Si','S'};{'Si'};{'Na','Mg','Al','P'}}
How can I delete all the rows which contain just one value, to obtain:
x={{'Na','Mg','Si'};{'Na','Mg','Si','S'};{'Na','Mg','Al','P'}}
Solution 1:[1]
You don't have a "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'}}
You can get the number of elements in each sub-cell with
N = cellfun( @numel, x );
Then remove sub-cells with a single element using
x = x( N > 1 );
This could be done in one line
x = x( cellfun(@numel, x) > 1 );
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Wolfie |
