How to search for substring in cell array and get the corresponding index then?
1 次查看(过去 30 天)
显示 更早的评论
Dear community,
i have a very big 3D cell array that contains either doubles or strings. I need to find the cells that contain the string EXPERIMENT with the given index of my cell array.
I already tried approaches like strcmp or strfind, but I am still stuck.
Below is a picture of a subset of the cell array.
Thank you in advance,
Paul
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1222747/image.png)
0 个评论
采纳的回答
Askic V
2022-12-7
Please have a look at the following example:
C1 = {'Smith','Chung','Morales' [4 5 6]; ...
'Sanchez','Peterson',1:15,'Adams';...
'Adams','Johnson',[2.1 4.2],'Adams'}
C2 = cellfun(@num2str,C1,'UniformOutput',false)
C3 = strfind(C2, 'Ada')
ind = ~cellfun('isempty', C3)
I think you should be able to use it in your own application. C1 becomes your val
0 个评论
更多回答(1 个)
GeeTwo
2022-12-7
If I'm understanding correctly,
cellfun(@numel,strfind(string(val),"EXPERIMENT"))
will give you a matrix with 1's where the string is found and 0's where it isn't, whether due to it being a string without "EXPERIMENT" or not a string at all.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!