In MATLAB (R2015b) I have a very large Cell C
containing multiple column vectors that can be simplified as:
C = [9000x1 double] [9000x1 double] {9000x1 cell} {9000x1 cell}
The last two columns in C
, the two cells (9000x1 cell), the first cell-column contains the words 'GREN'
or 'BLU'
, and the second cell-column contains the words 'OVR'
or 'UNDR'
randomly.
So, in my mind, for example the first four rows of C
may have the appearance of:
[ 123 54.3 'BLU' 'UNDR'; 125 51.3 'GREN' 'OVR'; 128 55.1 'GREN' 'UNDR'; 129 51.1 'BLU' 'OVR']
How can I filter out the rows that do NOT contain the words 'BLU'
and/or 'OVR'
? I.e. so that the example above becomes:
[ 123 54.3 'BLU' 'UNDR'; 125 51.3 'GREN' 'OVR'; 129 51.1 'BLU' 'OVR']
I've tried converting the cells into matrix format (cell2mat) and then filter the matrix without any luck. Thanks in advance!
using strcmp
:
C = { 123, 54.3 ,'BLU', 'UNDR'; 125, 51.3, 'GREN', 'OVR'; 128, 55.1, 'GREN', 'UNDR'; 129,51.1,'BLU','OVR'};
idxs = strcmp(C(:,3),'BLU') | strcmp(C(:,4),'OVR');
CC = C(idxs,:)