How to search in a text cell by a word ?
2 次查看(过去 30 天)
显示 更早的评论
i have a large data (text and numbers), i want to search for a word in a specific cell (contaning text) of a coloumn in all rows. a(:,6)
example
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149976/image.jpeg)
and then copy all the rows containing the word in a new file.
how i can do this ?
i try
j=1 for i=1:size(data,1) if isequal (data{i,6}, ' the word') d(j)=i j=j+i end end newdata=data(D,:);
0 个评论
采纳的回答
Star Strider
2015-5-9
The standard comparison functions used with numeric variables don’t work with strings. Consider using strcmp or its many friends (most of them linked to on that page). One of them should work for you.
2 个评论
Star Strider
2015-5-10
I don’t have your data so I can’t run your code or test this, but see if:
if strcmpi(alldata{i,6},'battery') % search for word "battery"
improves your code.
It uses the strcmpi (case-insensitive string comparison) to do the test.
更多回答(0 个)
另请参阅
类别
在 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!