Matlab finds a substring in an array of cells

I am trying to find arrays in my camera that should separate "HA" from their names. I found the function here, but it does not work for my problem. My cell looks like this:

'HA1'   'HA1'   'HA1'   'HA1'   'HA1'
'HA2'   'HA2'   'HA2'   'HA2'   'HA2'
'HA3'   'HA3'   'HA3'   'HA3'   'HA3'
'HA4'   'HA4'   'HA4'   'HA4'   'HA4'
'HA5'   'HA5'   'HA5'   'HA5'   'HA5'
'HA6'   'HA6'   'HA6'   'HA6'   'HA6'
'HA7'   'HA7'   'HA7'   'HA7'   'HA7'
'HA8'   'WA1'   'WA1'   'WA1'   'WA1'
'HA9'   'WA2'   'WA2'   'WA2'   'WA2'
'HA10'  'WA3'   'WA3'   'WA3'   'WA3'
'HA11'  'WA4'   'WA4'   'WA4'   'WA4'
'DA1'   'WA5'   'WA5'   'WA5'   'WA5'
'DA2'   []  []  []  'WA6'
'DA3'   []  []  []  'WA7'
'DA4'   []  []  []  'WA8'
'DA5'   []  []  []  'WA9'
'DA6'   []  []  []  'WA10'
[]  []  []  []  'WA11'
[]  []  []  []  'WA12'

I tried this function:

x = 'HA';
y = cellArray;
substrfind = @(x,y) ~cellfun(@isempty,strfind(y,x));
logicalArray = substrfind(x,y);

Im should get a boolean array as a result, which is really useful for my problem. But instead, I get this error message: "If any of the input arguments is an array of cells, the first should be an array of row cells, and the second should be an array of characters."

I do not understand what the error is, because the first input y is an array of cells, and the second character is x.

Hope you guys can help me with my problem! Thank you pending! Regards

+4
1

, C - . , , :

>> C(cellfun('isempty', C)) = {''};
>> logicalArray = ~cellfun('isempty', strfind(C, 'HA'))

strfind , . , - [] double, char. .

, double char (''), strfind.

:

>> logicalArray = cellfun(@(x)~isempty(strfind(x,'HA')), C)

.

+8

Source: https://habr.com/ru/post/1528075/


All Articles