Thanks to Bruno for the tip on the proper format for cellfun's 1st argument. I know it should have been obvious from dpb's example code, but I just lost track of the punctuations (not using anymous function much, and all). I confirmed that my approach to converting nonstring cells to strings works:
>> mixedCellArray = {
'adpo' 2134 []
0 [] 'daesad'
'xxxxx' 'dp' 'dpdpd'
}
mixedCellArray =
'adpo' [2134] []
[ 0] [] 'daesad'
'xxxxx' 'dp' 'dpdpd'
>> ~cellfun(@ischar,mixedCellArray)
ans =
0 1 1
1 1 0
0 0 0
>> mixedCellArray( ~cellfun(@ischar,mixedCellArray) ) = {''}
mixedCellArray =
'adpo' '' ''
'' '' 'daesad'
'xxxxx' 'dp' 'dpdpd'
>> cellfun(@ischar,mixedCellArray)
ans =
1 1 1
1 1 1
1 1 1
But I didn't bother following it through to find a substring. dpd's example works so much better. And being able to run it in Matlab allowed me to actually figure out what it does. For reference, here is his example, best viewed in fixed-width font:
>> mixedCellArray = {
'adpo' 2134 []
0 [] 'daesad'
'xxxxx' 'dp' 'dpdpd'
}
mixedCellArray =
'adpo' [2134] []
[ 0] [] 'daesad'
'xxxxx' 'dp' 'dpdpd'
>> ~cellfun( @isempty , ...
cellfun( @(x)strfind(x,'dp') , ...
mixedCellArray , ...
'uniform',0) ...
)
ans =
1 0 0
0 0 0
0 1 1
The inner cellfun is able to apply strfind to even numerical cells because, I presume, Matlab treats numerical arrays and strings the same way. A string is just an array of numbers representing the character codes. The outer cellfun identifies all cells for which the inner cellfun found a match, and the prefix tilde turns that into all cells for which there was NO match.
Thanks, dpb.